如何使用puppeteer选择此(html锚元素以单击并导航到Tutorial页面)查询?
我正在执行此操作,但它不起作用
const puppeteer = require('puppeteer');
const url = process.argv[2];
if (!url) {
throw "Please provide URL as a first argument";
}
async function run() {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
slowMo: 10,
args: ['--start-maximzed', '--disable-notifications']
});
const page = await browser.newPage();
await page.goto(url);
await page.waitForSelector(".python-navigation .navigation.menu .tier-1.element-3 a", {
visible: true
});
await page.click(".python-navigation .navigation.menu .tier-1.element-3 a");
await page.waitForSelector(".documentation-banner .download-buttons ", {
visible: true
});
const elem = await page.$$('.documentation-banner .download-buttons a');
await elem[0].click();
await page.waitForSelector(".contentstable", {
visible: true
});
elem = await page.$$('.contentstable')[0].$$('tbody')[0].$$('tr')[0].$$('td')[0].$$('p')[1];
await elem.click();
await page.pdf({path: 'pdfGenerated.pdf',format:"A4"});
console.log("Success");
browser.close();
}
run();
我应该写些什么代替这行elem = await page.$$('.contentstable')[0].$$('tbody')[0].$$('tr')[0].$$('td')[0].$$('p')[1];
?
单击元素可以使用此代码:
await page.click(".contentstable tbody tr td p:nth-child(2) a");