马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 azzzzzz 于 2020-3-22 00:11 编辑 import urllib.request
url = "http://www.ip111.cn/"
proxy_support = urllib.request.ProxyHandler({"http":"117.88.176.252:3000"})
headers = ("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
opener = urllib.request.build_opener(proxy_support)
opener.addheaders[headers]
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
html = response.read().decode("utf-8")
print(html)
报错信息:
Traceback (most recent call last):
File "D:\python 3.8\资料\爬虫学习\proxy_eg.py", line 10, in <module>
opener.addheaders[headers]
TypeError: list indices must be integers or slices, not tuple
按照小甲鱼教程这样写报错,网上找了很多都是这样写的,找手册上面找不到这个方法,不知道怎么回事求大佬解答! |