安装
npm install puppeteer puppeteer-core puppeteer-page-proxy
示例代码
//example.js
const puppeteer = require('puppeteer');
const useProxy = require('puppeteer-page-proxy');
// 隧道代理订单号
const proxyUser = "xxx";
// 密码,在用户中心 -- 隧道代理订单页面可查询到
const proxyPass = "xxx";
const proxy = `http://${proxyUser}:${proxyPass}@dyn.horocn.com:50000`;
(async () => {
const browser = await puppeteer.launch({
// 这里改为本地正确的谷歌浏览器路径
// Windows 参考路径:`${process.env.PROGRAMFILES}\\Google\\Chrome\\Application\\chrome.exe`
// Linux 参考路径:/opt/google/chrome/chrome
// macOS 参考路径:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
headless: false,
});
const page = await browser.newPage();
await useProxy(page, proxy);
await page.goto('https://whois.pconline.com.cn/ipJson.jsp?json=true');
//await browser.close();
})();
测试环境
- 操作系统:macOS Big Sur
- Chrome 浏览器:92.0.4515.159
- Node.js:v16.4.0
- puppeteer:^10.2.0
- puppeteer-core:^10.2.0
- puppeteer-page-proxy:^1.2.8
注意
- 请替换上面的路径为你本地合适的路径,如:executablePath
- 请记得修改上面的用户名和密码
转载请注明