python - 做一个好公民和网络抓取

标签 python screen-scraping scrapy

我有一个分为两部分的问题。

首先,我正在编写一个基于 CrawlSpider 的网络抓取工具Scrapy 中的蜘蛛。我的目标是抓取一个拥有数千条(可能达到数十万条)记录的网站。这些记录被埋在起始页下方 2-3 层。所以基本上我让蜘蛛从某个页面开始,爬行直到找到特定类型的记录,然后解析 html。我想知道有什么方法可以防止我的蜘蛛程序使站点重载?是否有可能以增量方式执行操作或在不同请求之间暂停?

其次,与此相关的是,是否有一种方法可以使用 Scrapy 来测试爬虫而不会对站点施加过度压力?我知道您可以在程序运行时将其终止,但是有没有办法让脚本在点击包含我要抓取的信息的第一页之类的内容后停止?

如有任何建议或资源,我们将不胜感激。

最佳答案

Is there possibly a way to do thing's incrementally

我正在使用 Scrapy 缓存功能来逐步抓取网站

HTTPCACHE_ENABLED = True

或者您可以使用新的 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/

相关文章:

python - 使用 K-Means 根据不同时间的不同读数对节点进行聚类

python - 如何在 Windows 7 上安装适用于 Python 3.5 或 3.3 的 pyodbc

c# - 如何从 Windows 应用程序中抓取数据网格

python - Pandas 抓取的数据在 Pandas 中不起作用

python - 我如何在 scrapy python 中编写我的自定义链接提取器

python - Scrapy 中的自定义文件管道从不下载文件,即使日志应该访问所有功能

python - 使用 cookie 进行 scrapy 身份验证登录

python - 我可以创建一个 `pytest.mark.failif` 吗?

python - 为什么我的验证准确率停留在 65% 左右?如何提高它?

screen-scraping - 抓取网站的最佳方法或工具是什么?