"); //-->
爬虫代理是网络爬虫不可缺少的一部分。当然在使用爬虫代理IP的时候需要了解这个IP是否有效。有效IP直接使用。无效的IP拉入黑名单不使用即可。那如何验证爬虫代理IP是否有效呢,网络上其实有很多种方式:
1、浏览器验证以火狐为例:打开火狐浏览器,在浏览器的右上角菜单列表中—选择—常规—网络设置—设置。把爬虫代理IP配置进去,然后填写好用户名和密码即可。代理信息设置完成后访问此http://current.ip.16yun.cn:802返回的就是代理IP的地址
2、CURL验证爬虫代理(IP隧道,保持IP不变)
用户可以指定IP隧道,用于连续请求场景
#!/bin/bash curl -H "Proxy-Tunnel: 12345" -v -x http://username:password@ip:port http://current.ip.16yun.cn:802
自定义隧道
可以在请求头中加入 Proxy-Tunnel: 数值*随机数值*, 不同的数值表示不同的隧道;在代理有效期内,当数值相同,使用的代理IP就相同
API代理
#!/bin/bash curl -x http://ip:port http://current.ip.16yun.cn:802
ip 代理IP
port 端口
const puppeteer = require('puppeteer'); // 代理服务器(产品官网 www.16yun.cn) const proxyServer = 'http://t.16yun.cn:31111'; const username = 'username'; const password = 'password'; (async() => { const browser = await puppeteer.launch({ args: [ '--proxy-server='+proxyServer+'','--no-sandbox', '--disable-setuid-sandbox' ]}); const page = await browser.newPage(); await page.authenticate({ username, password }); await page.goto('https://www.baidu.com'); const cookies = await page.cookies(); await console.log(cookies); await page.setViewport({width: 320, height: 480}); await page.screenshot({path: '/screenshots/full.png', fullPage: true}); await browser.close(); })();
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。