簡體   English   中英

時間表中的網頁抓取

[英]Web-Scraping of tables within a timetable

我對抓取網頁游戲還很陌生,但是作為一個項目的一部分,我正在嘗試從此時間表中抓取類的詳細信息https://www101.dcu.ie/timetables/feed.php?prog=case&per=2&week1= 19&week2 = 30&day = 7&hour = 1-20&template = Studprog我將嘗試使用jsoup,但不知道如何准確地解析數據,從而僅返回相關信息。 任何幫助或見識將不勝感激

您可以使用iconvcheerio

我做了一個功能性的例子供您查看:

const rp = require('request-promise');
const iconv = require('iconv-lite');
const cheerio = require('cheerio');

const getRequestDefault = (method) => (url) => 
    rp({
        encoding: null,
        method: method,
        uri: url,
        rejectUnauthorized: false
    })
        .then(html => {
            const $ = cheerio.load(
                iconv.decode(
                    new Buffer(html), "ISO-8859-1"
                )
            );

            return $;
        })

const getRows = () => 
    getRequestDefault('GET')(`https://www101.dcu.ie/timetables/feed.php?prog=case&per=2&week1=19&week2=30&day=7&hour=1-20&template=Studprog`)
        .then($ => {
            // Example
            $('table tbody tr')
                .toArray()
                .forEach(
                    a => {
                        console.log($(a).text());
                    }
                );
        });

getRows();

這將廢棄所有表的所有字段tr

您可以以此為起點。 只需將代碼復制到.js文件中,安裝依賴項並使用: node file.js

安裝依賴項: npm install cheerio iconv request request-promise

希望對您有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM