whowho 发表于 2021-1-18 20:11:09

为什么这段代码有问题

import urllib.request
import random

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

iplist = ['119.6.144.73:81','49.70.89.62:9999','60.167.20.198:1133','58.253.156.212:9999','36.251.147.43:9999']

proxy_support = urllib.request.ProxyHandler({'http':random.choice(iplist)})

opener = urllib.request.build_opener(proxy_support)
opener.addheaders = ['User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 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 "F:\python练习\poxy_eg.py", line 15, in <module>
    response = urllib.request.urlopen(url)
File "E:\python\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
File "E:\python\lib\urllib\request.py", line 514, in open
    req = meth(req)
File "E:\python\lib\urllib\request.py", line 1294, in do_request_
    for name, value in self.parent.addheaders:
ValueError: too many values to unpack (expected 2)

均昊山 发表于 2021-1-19 12:10:53

这网页都打不开

YunGuo 发表于 2021-1-19 15:41:02

这个台湾网站,在内地你打不开,另外你使用的几个代理ip都是免费代理ip吧,都超时没作用。
页: [1]
查看完整版本: 为什么这段代码有问题