代码如下:
import urllib.request
url=“http://218.92.191.43:38093”
proxy_support=urllib.request.ProxyHandler({‘http’:‘49.83.220.45:1080’})
opener=urllib.request.build_opener(proxy_support)
opener.addheaders=[(‘User-Agent’,‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER’)]
#urllib.request.install_opener(opener)
try:
res=opener.open(url)
except urllib.error.URLError as reason:
print(“访问出错为:”+str(reason))
else:
html=res.read().decode(“utf-8”)
print(html)
运行结果:访问出错为:<urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
后来尝试将proxy_support=urllib.request.ProxyHandler({‘http’:‘49.83.220.45:1080’})中的http改成https就可以爬取了,这是什么鬼!
结果测试根本没有用代理服务器爬取而是用本机ip进行爬取
python用代理服务器访问https网站可以,访问http网站就不行了
最新推荐文章于 2024-05-14 13:52:35 发布