|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码
- import urllib.request as u
- url='http://www.whatismyip.com.tw'
- pro=u.ProxyHandler({'http':'47.106.105.236:80'})
- opener=u.build_opener(pro)
- opener.addheaders[('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 Edg/103.0.1264.77')]
- u.install_opener(opener)
- response=u.urlopen(url)
- html=response.read().decode("utf-8")
- print(html)
复制代码
错误
- Traceback (most recent call last):
- File "D:\py\代理ip测验.py", line 7, in <module>
- opener.addheaders[('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 Edg/103.0.1264.77')]
- TypeError: list indices must be integers or slices, not tuple
复制代码
大佬们能看看是哪里的问题吗?
- import urllib.request as u
- url='http://www.whatismyip.com.tw'
- pro=u.ProxyHandler({'https':'47.106.105.236:80'})
- opener=u.build_opener(pro)
- opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 Edg/103.0.1264.77')]
- u.install_opener(opener)
- response=u.urlopen(url)
- html=response.read().decode("utf-8")
- print(html)
复制代码
|
|