|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
ip是https://www.xicidaili.com/西刺上的
代码如下:
import urllib.request
import random
url = 'https://www.ip.cn/'
iplist = ['14.20.235.46:808','223.119.182.192:53281']
proxy_support = urllib.request.ProxyHandler({'https':random.choice(iplist)})
opener = urllib.request.build_opener(proxy_support)
opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36')]
response=opener.open(url)
html =response.read().decode('utf-8')
print(html)
会报error,log如下:
Traceback (most recent call last):
File "D:/python/新建文件夹/12.py", line 11, in <module>
response=opener.open(url)
File "D:\python\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "D:\python\lib\urllib\request.py", line 640, in http_response
response = self.parent.error(
File "D:\python\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "D:\python\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "D:\python\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
请教下大神额,这是哪里出了问题呢? |
|