最近我开始使用 Puppeteer 爬行网络。下面是从商城中提取特定产品名称的代码。
\n\nconst puppeteer = require('puppeteer');\n\n(async () => {\n\n const width = 1600, height = 1040;\n\n const option = { headless: false, slowMo: true, args: [`--window-size=${width},${height}`] };\n\n const browser = await puppeteer.launch(option);\n const page = await browser.newPage();\n const vp = {width: width, height: height};\n await page.setViewport(vp);\n\n const navigationPromise = page.waitForNavigation();\n\n await page.goto('https://shopping.naver.com/home/p/index.nhn');\n await navigationPromise;\n await page.waitFor(2000);\n\n const textBoxId = 'co_srh_input';\n await page.type('.' + textBoxId, '\xec\x96\x91\xeb\xa7\x90', {delay: 100});\n await page.keyboard.press('Enter');\n\n await page.waitFor(5000);\n await page.waitForSelector('div.info > a.tit');\n\n const stores = …
Run Code Online (Sandbox Code Playgroud) javascript web-crawler node.js google-chrome-devtools puppeteer