我正在尝试抓取网站,该网站足够复杂以阻止机器人,我的意思是它只允许几个请求,之后 Scrapy 挂起。
问题1:有没有办法,如果Scrapy挂起,我可以从同一点重新启动我的爬行过程。
为了摆脱这个问题,我这样写了我的设置文件
BOT_NAME = 'MOZILLA'
BOT_VERSION = '7.0'
SPIDER_MODULES = ['yp.spiders']
NEWSPIDER_MODULE = 'yp.spiders'
DEFAULT_ITEM_CLASS = 'yp.items.YpItem'
USER_AGENT = '%s/%s' % (BOT_NAME, BOT_VERSION)
DOWNLOAD_DELAY = 0.25
DUPEFILTER=True
COOKIES_ENABLED=False
RANDOMIZE_DOWNLOAD_DELAY=True
SCHEDULER_ORDER='BFO'
这是我的程序:
class ypSpider(CrawlSpider):
name = "yp"
start_urls = [
SOME URL
]
rules=(
#These are some rules
)
def parse_item(self, response):
####################################################################
#cleaning the html page by removing scripts html tags
#######################################################
hxs=HtmlXPathSelector(response)
问题是我可以在哪里编写http代理,我是否必须导入任何与tor相关的类,我是Scrapy的新手,因为在这个小组中我学到了很多东西,现在我正在尝试学习“如何使用ip旋转或tor”
正如我们的一位成员所建议的,我启动了 tor 并将 HTTP_PROXY 设置为
set http_proxy=http://localhost:8118
但它抛出了一些错误,
failure with no frames>: class 'twisted.internet.error.ConnectionRefusedError' Connection was refused by other side 10061: No connection could be made because the target machine actively refused it.
所以我将 http_proxy 更改为
set http_proxy=http://localhost:9051
现在错误是
failure with no frames>: class 'twisted.internet.error.ConnectionDone' connection was closed cleanly.
我检查了 Firefox 网络设置,在那里我看不到任何 http 代理,但它使用的是 SOCKSV5,而是显示 127.0.0.1:9051。 (在 TOR 之前,它不需要代理)请帮助我,我仍然不明白如何通过 Scrapy 使用 TOR。
我应该使用哪个 TOR 包以及如何使用?
我希望我的两个问题都能得到解决
- 如果 scrapy 爬虫由于某种原因挂起(连接失败),我想从那里恢复服务本身
- 如何在Scrapy中使用轮换IP