【发布时间】:2021-01-27 01:55:39
【问题描述】:
我喜欢像 this 这样的 URL 卷曲。 (如果您没有该网站的 cookie,则该 URL 需要在欧盟国家/地区获得同意。)
我拼凑了一个执行此操作的 puppeteer 脚本,但在我看来它非常沉重且脆弱。有更好的解决方案吗?
#!/usr/bin/env node
const url = process.argv[2];
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(url)
await page.waitForSelector('.con-wizard > .wizard-body > #consent-text > .content-list > .list-item:nth-child(1)')
await page.click('.con-wizard > .wizard-body > #consent-text > .content-list > .list-item:nth-child(1)')
await page.waitForSelector('.con-wizard > .wizard-body > .actions > .consent-form > .primary')
await page.click('.con-wizard > .wizard-body > .actions > .consent-form > .primary')
const timeout = ((process.env.cfTimeout) || 20) * 1000
await page.waitFor(timeout);
const html = await page.content();
console.log(html);
await browser.close()
})()
【问题讨论】:
标签: curl web-scraping cookies puppeteer wget