我有一个分为两部分的问题。
首先,我正在编写一个基于 CrawlSpider 的网络抓取工具Scrapy 中的蜘蛛。我的目标是抓取一个拥有数千条(可能达到数十万条)记录的网站。这些记录被埋在起始页下方 2-3 层。所以基本上我让蜘蛛从某个页面开始,爬行直到找到特定类型的记录,然后解析 html。我想知道有什么方法可以防止我的蜘蛛程序使站点重载?是否有可能以增量方式执行操作或在不同请求之间暂停?
其次,与此相关的是,是否有一种方法可以使用 Scrapy 来测试爬虫而不会对站点施加过度压力?我知道您可以在程序运行时将其终止,但是有没有办法让脚本在点击包含我要抓取的信息的第一页之类的内容后停止?
如有任何建议或资源,我们将不胜感激。
最佳答案
Is there possibly a way to do thing's incrementally
我正在使用 Scrapy 缓存功能来逐步抓取网站
或者您可以使用新的 0.14 功能 Jobs: pausing and resuming crawls
or put a pause in between different requests?
检查此设置:
DOWNLOAD_DELAY
RANDOMIZE_DOWNLOAD_DELAY
is there a method with Scrapy to test a crawler without placing undue stress on a site?
您可以在 Scrapy shell 中尝试调试您的代码
I know you can kill the program while it runs, but is there a way to make the script stop after hitting something like the first page that has the information I want to scrape?
另外,您可以调用scrapy.shell.inspect_response随时在您的蜘蛛中。
Any advice or resources would be greatly appreciated.
Scrapy 文档是最好的资源。
关于python - 做一个好公民和网络抓取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8542552/