我在阅读时遇到一些问题一些网址。
我尝试使用此问题的答案Using an HTTP PROXY - Python ,但它没有帮助,我收到错误urllib2.URLError: <urlopen error [Errno 10060]
我有一个网址列表
yandex.ru/search?text=авито&lr=47
yandex.ru/search?text=цветок%20киддиленд%20музыкальный&lr=47
dns-shop.ru/product/c7bf1138670f3361/rul-hori-racing-wheel
dns-shop.ru/product/c7bf1138670f3361/rul-hori-racing-wheel#opinion
kaluga.onlinetrade.ru/catalogue/ruli_dgoystiki_geympadi-c31/hori/reviews/rul_hori_racing_wheel_controller_ps_4_ps4_020e_acps440-274260.html
kazan.onlinetrade.ru/catalogue/ruli_dgoystiki_geympadi-c31/hori/reviews/rul_hori_racing_wheel_controller_xboxone_xbox_005u_acxone34-274261.html
ebay.com
代码看起来像
for url in urls:
proxy = urllib2.ProxyHandler({"http":"http://61.233.25.166:80"})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
try:
html = urllib2.urlopen(url).read()
except ValueError or urllib2:
url = 'http://www.' + url
html = urllib2.urlopen(url).read()
我也试试
s = requests.Session()
s.proxies = {"http": "http://61.233.25.166:80"}
for url in urls:
url = 'http://www.' + url
r = s.get(url)
print(r.text)
它会让我回头
requests.exceptions.ProxyError: HTTPConnectionPool(host='61.233.25.166', port=80): Max retries exceeded with url: http://www.yandex.ru/search?text=%D0%B8%D0%B3%D1%80%D1%83%D1%88%D0%BA%D0%B0%20%22%D0%B2%D0%B5%D1%81%D0%B5%D0%BB%D0%B0%D1%8F%20%D0%B3%D1%83%D1%81%D0%B5%D0%BD%D0%B8%D1%86%D0%B0%22%20keenway%20%D0%BE%D1%82%D0%B7%D1%8B%D0%B2%D1%8B&lr=47 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x047D1090>: Failed to establish a new connection: [Errno 10060] \xcf\xee\xef\xfb\xf2\xea\xe0 \xf3\xf1\xf2\xe0\xed\xee\xe2\xe8\xf2\xfc \xf1\xee\xe5\xe4\xe8\xed\xe5\xed\xe8\xe5 \xe1\xfb\xeb\xe0 \xe1\xe5\xe7\xf3\xf1\xef\xe5\xf8\xed\xee\xe9, \xf2.\xea. \xee\xf2 \xe4\xf0\xf3\xe3\xee\xe3\xee \xea\xee\xec\xef\xfc\xfe\xf2\xe5\xf0\xe0 \xe7\xe0 \xf2\xf0\xe5\xe1\xf3\xe5\xec\xee\xe5 \xe2\xf0\xe5\xec\xff \xed\xe5 \xef\xee\xeb\xf3\xf7\xe5\xed \xed\xf3\xe6\xed\xfb\xe9 \xee\xf2\xea\xeb\xe8\xea, \xe8\xeb\xe8 \xe1\xfb\xeb\xee \xf0\xe0\xe7\xee\xf0\xe2\xe0\xed\xee \xf3\xe6\xe5 \xf3\xf1\xf2\xe0\xed\xee\xe2\xeb\xe5\xed\xed\xee\xe5 \xf1\xee\xe5\xe4\xe8\xed\xe5\xed\xe8\xe5 \xe8\xe7-',)))
哪里有错误?
答案 0 :(得分:0)
有些代理人没有工作。
我使用urllib
代替urllib2
和
for url in urls:
proxies = {'http': 'http://109.172.106.3:9999', 'http': 'http://62.113.208.183:3128', 'http': 'http://178.22.148.122:3129', 'http': 'http://217.17.46.162:3128'}
url = 'http://www.' + url
html = urllib.urlopen(url, proxies=proxies).read()
它对我有用