爬虫课程的一点问题,希望大家看一看
import urllib.requesturl = 'http://45.32.164.128/ip.php'
response = urllib.request.urlopen(url)
print(response.read().decode('utf-8'))
proxy_support = urllib.request.ProxyHandler({'http': '113.59.99.138:8910'})
opener = urllib.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/81.0.4044.138 Safari/537.36')]
response = opener.open(url)
print(response.read().decode('utf-8'))
file:///C:/Users/汪振/AppData/Roaming/Tencent/Users/1281359990/QQ/WinTemp/RichOle/Q@7C%25$IN7O8G]E@XCW%60CYEO.png报错:
Traceback (most recent call last):
opener = opener.addheaders[('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36')]
TypeError: list indices must be integers or slices, not tuple
页:
[1]