"); //-->
360浏览器设置代理IP方案:
1、打开浏览器点开代理服务器设置
2、在代理服务器列表中,添加获取的代理IP
3、添加代理后,可在代理菜单中选择使用哪个代理
爬虫程序设置代理IP的方案:
这里以常见的python爬虫举例:
#! -*- encoding:utf-8 -*- import base64 import sys import random PY3 = sys.version_info[0] >= 3 def base64ify(bytes_or_str): if PY3 and isinstance(bytes_or_str, str): input_bytes = bytes_or_str.encode('utf8') else: input_bytes = bytes_or_str output_bytes = base64.urlsafe_b64encode(input_bytes) if PY3: return output_bytes.decode('ascii') else: return output_bytes class ProxyMiddleware(object): def process_request(self, request, spider): # 代理服务器(产品官网 www.16yun.cn) proxyHost = "t.16yun.cn" proxyPort = "31111" # 代理验证信息 proxyUser = "username" proxyPass = "password" request.meta['proxy'] = "http://{0}:{1}".format(proxyHost,proxyPort) # 添加验证头 encoded_user_pass = base64ify(proxyUser + ":" + proxyPass) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass # 设置IP切换头(根据需求) tunnel = random.randint(1,10000) request.headers['Proxy-Tunnel'] = str(tunnel)
其实浏览器设置代理和爬虫程序这是代理IP最大的区别就在于,一个只适合于爬虫业务量小,浏览器配置代理只是偶尔访问。爬虫程序配置代理IP适用于想要快速稳定大量采集爬虫数据,适用于公司企业爬虫业务。
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。