Puppeteer 简单使用

const puppeteer = require('puppeteer');


(async () => {
  //无头方便调试
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  //打开网页
  await page.goto('http://www.waitingfy.com/wp-login.php');
  //id为user_login的input输入文字
  await page.type('#user_login', '****',{delay:100})
  await page.type('#user_pass', '****',{delay:100})
  //点击
  await page.click('#wp-submit')

  await page.goto('http://www.liuyiqi.cn/');
  await page.waitForSelector('#logo');
  //得到属性
  const text = await page.$eval('#logo', el => el.textContent)
  console.log(text)

})();

VSCode 安装Code Runner 可以方便运行node js代码。 或者node xxxx.js 来运行

http://www.waitingfy.com/archives/4086

Tags:

4086

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.