代理IP爬取之快代理

核心代码

npm index.js

const puppeteer = require('puppeteer');
(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://www.kuaidaili.com/ops/');
    const res = await page.evaluate(() => {
        const text = (v, selector) => {
            return v.querySelector(selector) && v.querySelector(selector).innerText;
        };
        const allHostInfo = Array.from(
            document.querySelectorAll("#freelist tbody tr")
        );
        const data = [];
        allHostInfo.map(v => {
            const obj = {
                host: text(v, "td:nth-child(1)"),
                port: text(v, "td:nth-child(2)"),
                address: text(v, "td:nth-child(6)"),
            };
            data.push(obj);
        });
        return data;
    });
    console.log(res);
    await page.waitFor(2 * 1000);
    await browser.close();
})();

npm package.json

{
  "name": "crack-alipay",
  "version": "1.0.0",
  "description": "crack",
  "main": "src/index.js",
  "scripts": {
    "v1": "node src/index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^10.11.7"
  },
  "dependencies": {
    "puppeteer": "^1.18.1"
  }
}

运行方式:npm run v1

运行结果

代理IP爬取之快代理_第1张图片

你可能感兴趣的:(js,代理IP,爬虫,快代理)