Nic*_*ngs 7 chromium node.js puppeteer
我正在尝试使用Puppeteer进行一些Web抓取,但是脚本似乎无法找到我要寻找的选择器。基本上这段代码:
const puppeteer = require('puppeteer');
let scrape = async () => {
const year = 18;
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://cobbcounty.org/index.php?option=com_wrapper&view=wrapper&Itemid=2008');
await page.waitFor(5000);
var id = '';
for(i=0;i<10000;i++){
id = i;
await page.click('#txtCase');
await page.keyboard.type(year + '-P-' + id);
await page.select('#lstDoc','Estate');
}
}
scrape().then((value) => {
console.log('script ended');
});
Run Code Online (Sandbox Code Playgroud)
给我这个错误:
(node:31125) UnhandledPromiseRejectionWarning: AssertionError
[ERR_ASSERTION]: No node found for selector: #txtCase
Run Code Online (Sandbox Code Playgroud)
据我所知,#txtCase是页面上的实际选择器,所以我不知道为什么木偶找不到它。如果有人可以向我解释我在做什么错,那将非常有帮助。
据我所知,#txtCase是页面上的实际选择器,所以我不知道为什么木偶找不到它。
尝试加载页面并使用控制台查找该元素。
document.querySelector('#txtCase')
null
Run Code Online (Sandbox Code Playgroud)
不在那里 我知道您可以在右键单击检查该文本字段时看到它,但是它嵌套在iframe中。您需要访问该框架,然后找到按钮,然后单击它。
const frame = await page.frames().find(f => f.name() === 'iframe');
const button = await frame.$('#txtCase');
button.click();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7323 次 |
| 最近记录: |