爬虫练习URLError问题
旧版54课件案列出问题,麻烦大佬看下:#代码
import urllib.request
url = "http://www.whatismyip.com.tw/"
proxy_support = urllib.request.ProxyHandler({"http":"222.74.73.202:42055"})
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/107.0.0.0 Safari/537.36")}
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
html = response.read().decode("utf-8")
print(html)
#运行结果
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\python\homework\爬虫练习\proxy-eg.py", line 13, in <module>
response = urllib.request.urlopen(url)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 519, in open
response = self._open(req, data)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1377, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。> 不会爬虫{:10_266:} zhangjinxuan 发表于 2022-12-2 21:26
不会爬虫
{:5_96:}
http 那改成 https
Twilight6 发表于 2022-12-4 09:55
http 那改成 https
谢谢~~,现在可以通过了,我还有个问题,为啥我不管设不设置代理ip,访问网站:https://www.whatismyip.com.tw/
给的ip都是:59.39.150.75 CN 这一个Ip地址 lxping 发表于 2022-12-4 12:29
谢谢~~,现在可以通过了,我还有个问题,为啥我不管设不设置代理ip,访问网站:https://www.whatismyip.c ...
你 ip 也要改成 https
页:
[1]