python
python使用代理IP访问地址
python使用代理IP访问地址
这篇文章跟大家分享Python使用代理IP访问地址,从而达到伪装的目的,下面代码仅供参考,不可用于其他非法用途,代码如下:
#!/usr/bin/python # -*- coding: UTF-8 -* # 引入模块 from urllib import request # 组装访问URL url = "目标地址" # 开始执行 try: proxy_support = request.ProxyHandler({"https":"99.80.88.229:80"}) opener = request.build_opener(proxy_support) opener.addheaders = [ ('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'), ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'), ('Accept-Encoding', 'gzip, deflate, br'), ('Accept-Language', 'zh-CN,zh;q=0.9'), ('Cache-Control', 'max-age=0'), ('Connection', 'keep-alive') ] request.install_opener(opener) request.urlopen(url, timeout=5) except IOError: print("访问失败") else: print("访问成功")
这样就是最简单的通过代理IP访问目标地址。
0条评论