【发布时间】:2017-11-06 09:02:02
【问题描述】:
我以前从谷歌获取信息,我知道我会在几次请求后阻止,这就是我试图通过代理的原因。对于我使用的代理 来自此链接的 ProxyBroker: The Link
但是,如果我使用代理,谷歌会返回 503。如果我点击错误,谷歌会显示我的 IP,而不是代理 IP。
这是我尝试过的:
usedProxy = self.getProxy()
if usedProxy is not None:
proxies = {"http": "http://%s" % usedProxy[0]}
headers = {'User-agent': 'Mozilla/5.0'}
proxy_support = urlrequest.ProxyHandler(proxies)
opener = urlrequest.build_opener(proxy_support, urlrequest.HTTPHandler(debuglevel=1))
urlrequest.install_opener(opener)
req = urlrequest.Request(search_url, None, headers)
with contextlib.closing(urlrequest.urlopen(req)) as url:
htmltext = url.read()
我尝试过使用 http 和 https。
即使请求进展顺利,我也会收到带有以下消息的 503:
send: b'GET http://www.google.co.in/search?q=Test/ HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: www.google.co.in\r\nUser-Agent: Mozilla/5.0\r\nConnection: close\r\n\r\n'
reply: 'HTTP/1.1 302 Found\r\n'
header: Date header: Server header: Location header: Pragma header: Expires header: Cache-Control header: Content-Type header: Content-Length header: X-XSS-Protection header: X-Frame-Options header:
>Connection send: b'GET http://ipv4.google.com/sorry/index?continue=http://www.google.co.in/search%3Fq%3DTest/&q=EgTCDs9XGMbOgNAFIhkA8aeDS0dE8uXKu31DEbfj5mCVdhpUO598MgFy HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: ipv4.google.com\r\nUser-Agent: Mozilla/5.0\r\n
>Connection: close\r\n\r\n'
reply: 'HTTP/1.1 503 Service Unavailable\r\n'
如果没有发生上述错误,我最终得到以下错误:
>[Errno 54] Connection reset by peer
我的问题是:
-
每次我的IP都是来自错误链接的IP而不是代理IP吗?
-
如果每次主机 IP 都显示在来自 google 的错误消息中并且 问题来自代理,如何绕过该错误?
【问题讨论】:
标签: python web-scraping proxy