|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import random
url = 'http://www.whatismyip.com.tw'
iplist = ['39.137.46.76:80', '39.137.69.6:80', '39.137.69.6:8080', '47.100.176.20:8080']
proxy_support = urllib.request.ProxyHandler({'http':random.choice(iplist)})
opener = urllib.request.build_opener(proxy_support)
opener.addhead = ['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']
urllib.request.install_opener(opener)
respond = urllib.request.urlopen(url)
html = respond.read().decode('utf-8')
print(html)
以上是我跟着小甲鱼老师敲的代码 报的错误在下面
E:\代码\小甲鱼爬虫教学\venv\Scripts\python.exe E:/代码/小甲鱼爬虫教学/proxy_eg.py
Traceback (most recent call last):
File "E:/代码/小甲鱼爬虫教学/proxy_eg.py", line 13, in <module>
respond = urllib.request.urlopen(url)
File "E:\python3.7.2\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "E:\python3.7.2\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "E:\python3.7.2\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "E:\python3.7.2\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "E:\python3.7.2\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "E:\python3.7.2\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 502: Bad Gateway
|
|