初始化项目
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
const puppeteer = require('puppeteer-core');
|
||||
|
||||
(async () => {
|
||||
const args = process.argv.slice(2); // 从第三个参数开始获取
|
||||
const server = args[1];
|
||||
const port = args[2];
|
||||
const browser = await puppeteer.launch({executablePath: '/usr/bin/google-chrome-stable',args: ['--no-sandbox','--proxy-server='+server+':'+port],waitUntil: 'networkidle0'});
|
||||
const page = await browser.newPage();
|
||||
const url = args[0];
|
||||
await page.goto(url);
|
||||
const title = await page.title();
|
||||
//等待元素出现
|
||||
await page.waitForSelector('[class*=headerTitle]')
|
||||
const result = await page.$eval('[class*=headerTitle]', el => el.textContent);
|
||||
//await page.screenshot({ path: 'example.png' }); // 页面截图 example.png
|
||||
console.log(result);
|
||||
//console.log(title);
|
||||
//console.log(text);
|
||||
// 等待1秒
|
||||
// await page.waitForTimeout(500);
|
||||
// // 或者使用 waitForSelector 等待元素出现
|
||||
// // await page.waitForSelector('#myElement');
|
||||
// const content = await page.content();
|
||||
// console.log(content);
|
||||
await browser.close();
|
||||
})();
|
||||
Reference in New Issue
Block a user