我正在尝试抓取网站,它足够复杂以阻止机器人,我的意思是它只允许一些请求,在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'
Run Code Online (Sandbox Code Playgroud)
这是我的计划:
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)
Run Code Online (Sandbox Code Playgroud)
问题是我可以编写http代理的地方,并且我必须导入任何与tor相关的类,我是Scrapy的新手因为这个小组我学到了很多东西,现在我正在努力学习"如何使用ip rotation or tor"
正如我们的一位成员建议的那样,我开始使用和设置HTTP_PROXY
set http_proxy=http://localhost:8118
Run Code Online (Sandbox Code Playgroud)
但是它会抛出一些错误,
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.
Run Code Online (Sandbox Code Playgroud)
所以我把http_proxy更改为
set http_proxy=http://localhost:9051
Run Code Online (Sandbox Code Playgroud)
现在错误是
failure with no frames>: class 'twisted.internet.error.ConnectionDone' connection was closed cleanly.
Run Code Online (Sandbox Code Playgroud)
我检查了firefox网络设置,在那里我看不到任何http代理,而是使用SOCKSV5,它显示127.0.0.1:9051.(在TOR之前它没有代理工作)请帮助我,我仍然不了解如何通过Scrapy使用TOR.我应该使用哪一套TOR以及如何使用?我希望我的两个问题都能得到解决
TOR 本身不是 http 代理,端口 8118 和连接拒绝错误表明您没有正确运行 privoxy[1]。尝试正确设置 privoxy,然后使用环境变量重试http_proxy=http://localhost:8118。
我已经使用 privoxy 和 scrapy 成功完成了 TOR 爬行。