gpt4 book ai didi

java - 解析来自维基百科 API 的响应

转载 作者:行者123 更新时间:2023-11-29 03:26:49 25 4
gpt4 key购买 nike

我正在尝试解析来自维基百科 API (MediaWiki) 的响应。我使用的 URL 的形式是 -

https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=Argo_(2012_film)

api 的响应在 xml 标记内包含维基百科内容,看起来像:(这只是一个不完整的示例)

{{Use mdy dates|date=October 2012}} {{Infobox film | name = Argo | image = 
Argo2012Poster.jpg | alt = <!-- See: WP:ALT --> | caption = Theatrical release poster |
tagline = "The movie was fake. The mission was real." | director = [[Ben Affleck]] |
producer = [[Grant Heslov]]<br />Ben Affleck<br />[[George Clooney]] | based on = {{Based
on|''The Master of Disguise''|[[Tony Mendez|Antonio J. Mendez]]}}<br />{{Based on|''The
Great Escape''|[[Joshuah Bearman]]}} | screenplay = [[Chris Terrio]] | starring = Ben
Affleck<br />[[Bryan Cranston]]<br />[[Alan Arkin]]<br />[[John Goodman]] | music =
[[Alexandre Desplat]] | cinematography = [[Rodrigo Prieto]] | editing = [[William
Goldenberg]] | studio = [[Graham King|GK Films]]<br />[[Smokehouse Pictures]] | distributor =
[[Warner Bros.]] | released = {{Film date|2012|08|31|Telluride Film
Festival|2012|10|12|United States}} | runtime = 120 minutes<ref> ...continued

这看起来不像 JSONXML,我该如何解析它?

最佳答案

如果要将内容解析为 HTML,请将 &rvparse 添加到查询中。

例如当你执行查询时

https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=Argo_%282012_film%29&rvparse

响应包含如下内容(跳过信息框后):

<i><b>Argo</b></i> is a 2012 American <a href="/wiki/Political_thriller"
title="Political thriller">political thriller</a> film directed by <a
href="/wiki/Ben_Affleck" title="Ben Affleck">Ben Affleck</a>.

关于java - 解析来自维基百科 API 的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20597005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com