123666666 发表于 2020-12-25 15:47:07

055.论一只爬虫的修养3,代理这里看不懂

import urllib.request

url='http:;//www.whatismyip.com。tw'

proxy_support=urllib.request.ProxyHandler({'http':'171.35.169.191:9999'})

opener=urllib.request.build_opener(proxy_support)
opener.addhead=[('User-Agent','Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Mobile Safari/537.36 Edg/86.0.622.63')]

urllib.request.install_opener(opener)

response=urllib.request.urlopen(url)

html=response.read().decode('utf-8')

print(html)
看不懂错在哪里

================= RESTART: C:\Users\ccj\Desktop\python\proxy.py ================
Traceback (most recent call last):
File "C:\Users\ccj\Desktop\python\proxy.py", line 12, in <module>
    response=urllib.request.urlopen(url)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 522, in open
    req = meth(req)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 1274, in do_request_
    raise URLError('no host given')
urllib.error.URLError: <urlopen error no host given>
>>>

suchocolate 发表于 2020-12-25 17:04:08

本帖最后由 suchocolate 于 2020-12-25 17:08 编辑

url = 'http://www.whatismyip.com.tw'
你的代码里的代理服务器不能用,建议新手先不用代理练习。

123666666 发表于 2020-12-25 18:11:17

suchocolate 发表于 2020-12-25 17:04
你的代码里的代理服务器不能用,建议新手先不用代理练习。

好的
页: [1]
查看完整版本: 055.论一只爬虫的修养3,代理这里看不懂