我应该多久查询一次文章,这样我的爬虫才不会被禁止?

How frequent should I query for an article so my crawler doesn't get banned?

我需要下载每个主要广泛使用的语言维基百科中每篇文章的第一段。最好是没有格式的纯文本。

我找到这个 URL:

https://en.wikipedia.org/w/api.php?action=query&format=json&titles=Socrates&prop=extracts&exintro&explaintext

不幸的是,我必须知道每篇文章的标题。所以,我想我可以使用 pageid 代替:

https://en.wikipedia.org/w/api.php?action=query&format=json&pageids=25664190&prop=extracts&exintro&explaintext

pageids=0 开始递增直到 pageids=INT_MAX.

对于另一种广泛使用的语言,如德语,我可以简单地将域更改为 de:

https://de.wikipedia.org/w/api.php?action=query&format=json&pageids=4649&prop=extracts&exintro&explaintext

最后的URL是:

https://%LLD%.wikipedia.org/w/api.php?action=query&format=json&pageids=%PAGE_ID%&prop=extracts&exintro&explaintext

在哪里

LLD = Low level domain of the country

PAGE_ID = Integer

我无法理解数据转储,这是我找到的完成这项工作的最简单方法。因为,我真的不想在说 10,000 篇文章后让我的 IP 被禁止,我应该多久抓取一个不同的 PAGE_ID?

我需要一个指标,以便尽可能提高性能。

主要编辑

There is no hard and fast limit on read requests, but we ask that you be considerate and try not to take a site down. Most sysadmins reserve the right to unceremoniously block you if you do endanger the stability of their site.

If you make your requests in series rather than in parallel (i.e. wait for the one request to finish before sending a new request, such that you're never making more than one request at the same time), then you should definitely be fine. Also try to combine things into one request where you can (e.g. use multiple titles in a titles parameter instead of making a new request for each title

API 常见问题解答指出每个 API 请求可以检索 50 页。

每 X 时间抓取 50 个 pageid 系列中的总共 70,000,000 个 pageid 将花费:

(70,000,00 / 50) * 200ms = 3 days

(70,000,00 / 50) * 500ms = 8 days

(70,000,00 / 50) * 1sec = 16 days

我200ms选一次肯定没问题吗?

我不会使用 URL 本身,而是在每个页面的页眉中使用 Open Graph 标签。维基百科有 og:titleog:imageog:type 的标签。如果您需要有关开放图谱协议的帮助,请参阅 https://ogp.me/。至于您的 IP 禁令,我真的不会太担心。维基百科被数百万人使用,除非您使用机器人进行恶意操作 activity 被禁止的可能性很小。

看起来实际上在处理文章时有足够的延迟(解析 json 并将其存储在某处或什至只是将其存储在某处),因此一个接一个的调用永远不会给服务器带来足够的压力。

一篇有效的文章(全文)需要大约 250 毫秒才能完成,exchars=1200(每篇文章的最大字符数)。