gpt4 book ai didi

python - 在网站的谷歌缓存上使用 Scrapy

转载 作者:太空狗 更新时间:2023-10-30 01:31:31 24 4
gpt4 key购买 nike

在“避免被禁止”标题下,Scrapy documentation advises :

if possible, use Google cache to fetch pages, instead of hitting the sites directly

指的是http://www.googleguide.com/cached_pages.html ,最后更新于 2011 年。

我正在尝试这样做,以抓取一个需要我无法绕过的验证码的网站。然而,谷歌随后又产生了同样的问题。

我使用这个中间件让蜘蛛停留在链接的 Google 缓存版本上:

class GoogleCacheMiddleware(object):
def process_request(self, request, spider):
if spider.use_google_cache == True and 'googleusercontent' not in request.url:
new_url = 'https://webcache.googleusercontent.com/search?q=cache:' + request.url
request = request.replace(url=new_url)
return request

在蜘蛛本身中,我使用以下设置礼貌地爬行:

custom_settings = {
'AUTOTHROTTLE_ENABLE' :True,
'CONCURRENT_REQUESTS' : 2, # or 1
'DOWNLOAD_DELAY' : 8 # increased this to as much as 10
}

我还尝试在原始网站和该网站的 Google 缓存版本上使用 Selenium。这有时会成功爬取几分钟并返回数据,但最终会落在 https://support.google.com/websearch/answer/86640。 ,其中指出 Google 从您的计算机网络检测到“异常流量”,并需要验证码才能继续。

Scrapy 文档似乎与 Google 使用条款有冲突,我说的对吗?无论哪种方式,是否有推荐的方法来绕过验证码,或者尽管有此限制,还是从网站的 Google 缓存中完成抓取?

更新,7-9-18:

当这个蜘蛛在一周或更长时间内运行几次时,它最终会产生完整或更完整的结果,这显然是因为最初抓取的 URL 在每次抓取时都会发生变化并在验证码启动之前成功。如果有人知道与文档或特定的解决方法。

最佳答案

我不太熟悉 Scrapy,但似乎该网站一定是阻止了缓存 View 。您是否尝试过使用 https://www.seoweather.com/google-cache-search/ 检查缓存?

不过,如果您要使用代理,最好是反向连接代理,那么您可以绕过 Google 的屏蔽,因为在抓取 Google 时您会需要很多东西。

另一种选择可能是尝试抓取 https://archive.org/web/页面的版本?事实上,他们甚至有一个你可以使用的 API https://archive.org/help/wayback_api.php

关于python - 在网站的谷歌缓存上使用 Scrapy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50555545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com