从 API 获取维基百科页面段落
如何从 Wikipedia API 获取段落页面?
例如,我想得到以下段落: https://fr.wikipedia.org/wiki/Douarnenez#Urbanisme
我是只能通过以下方式获取整个页面:
https://fr.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&titles=Douarnenez&formatversion=2&rvprop=content&rvslots=*
How to get paragraph page from Wikipedia API ?
For instance, I'd like to get the following paragraph:
https://fr.wikipedia.org/wiki/Douarnenez#Urbanisme
I'm only able to get the entire page with:
https://fr.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&titles=Douarnenez&formatversion=2&rvprop=content&rvslots=*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
学分:回答:如何通过维基百科 api 获取特定部分的文本 - 作者:Florian
我按顺序执行了以下步骤获取您需要的信息。
首先,获取您想要获取的部分的索引 - 为此,使用此端点获取 wiki 页面的部分:
这是 API 沙箱链接 您可以尝试一下。
在您的具体情况下,我相信它是
index=10
:然后,使用下一个端点来获取给定部分中的文本:
结果如下 - 这是 API链接沙箱:
Credits: answer to: How to get a text of a specific section via wikipedia api - by Florian
I followed these steps in order to get the information you need.
First, get the index of the section you want to get - for that, use this endpoint for get the sections of the wiki page:
Here is the API sandbox link you can try out.
In your specific case, I believe it's
index=10
:Then, use this next endpoint for get the text in the given section:
The result is as follows - here is the link of the API sandbox:
您可以使用正则表达式来过滤掉您的段落。这并不漂亮,但有效。
例如:
这将选择从 Urbanism 段落标题后面开始并在下一个段落标题之前结束的所有内容。请参阅:https://regex101.com/r/LlGSay/1
You can use Regex to filter out your paragraph. That's not beautiful, but works.
For example:
This selects everything starting behind the headline of the Urbanism paragraph and ending before the next paragraph headline. See: https://regex101.com/r/LlGSay/1