我是 puppeteer 的新手,我正在嘗試從下拉選單中單擊選擇器 
- 當我使用 DevTools 時,沒有為
.mat-option ng-star-inserted mat-active選擇器回傳任何元素,但是我可以用#mat-option-0選擇器找到所需的元素,或者我可以使用更長的版本,但必須.在每個類之前使用一個點 ( ) 并像這樣洗掉它們之間的空格.mat-option.ng-star-inserted.mat-active,你可以
我用這個腳本到達那里:
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://www.game.co.uk/en/-2640058?cm_sp=NintendoFormatHub-_-Accessories-_-espot-_-PikaCase'); await console.log('Users navigated to site :)'); await page.waitForSelector('.cookiePolicy_inner--actions'); await page.click('.cookiePolicy_inner--actions'); await page.waitForSelector('.addToBasket'); await page.click('.addToBasket'); await page.waitForSelector('.secure-checkout'); await page.click('.secure-checkout'); await page.waitForSelector('.cta-large'); await page.click('.cta-large'); await page.goto('https://checkout.game.co.uk/contact'); await page.waitForSelector('.mat-form-field-infix'); await page.click('.mat-form-field-infix'); await page.waitForSelector('#mat-option-0'); await page.click('#mat-option-0'); })();但是,這仍然不理想,因為:
- 你通過點擊來處理 cookie 欄,嘗試找到一種不點擊的方法;也許注入一個禁用 cookie 欄的 cookie(如果可能)
- the code is one big piece that is perhaps ok for now and this example but might become unmaintainable if you keep adding lines to it; try to reuse code in functions and methods
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/344506.html標籤:javascript 节点.js 网页抓取 机器人 傀儡师
上一篇:無法抓取“查看詳細資訊”按鈕鏈接作為頁面“https://www.bmstores.co.uk/stores?location=KA8 9BF”的串列
