基本上,我試圖拉入像
筆記:
如果您想將此腳本用作自定義函式,那么下面的腳本怎么樣?在這種情況下,請將自定義功能放入
=SAMPLE()單元格中。function SAMPLE() { const maxPage = 10; // From your question, the max page number is 10. const reqs = [...Array(maxPage)].map((_, i) => ({ url: `https://letterboxd.com/prof_ratigan/list/top-1000-films-of-all-time-calculated/detail/page/${i 1}/`, muteHttpExceptions: true })); return UrlFetchApp.fetchAll(reqs).flatMap((r, i) => { if (r.getResponseCode() != 200) { return [["Values couldn't be retrieved.", reqs[i].url]]; } const $ = Cheerio.load(r.getContentText()); const ar = $('li > div.film-detail-content > h2 > a , small > a').toArray(); return [...Array(Math.ceil(ar.length / 2))].map((_) => { const temp = ar.splice(0, 2); return [$(temp[0]).text().trim(), Number($(temp[1]).text().trim())]; }); }); }
筆記:
- 此示例腳本適用于 URL 中的當前 HTML。如果站點的規格發生更改,則可能無法使用此腳本。請注意這一點。
參考:
- fetchAll(請求)
- Cheerio 用于 Google Apps 腳本
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/493919.html
