首页 > 解决方案 > 如何使用维基百科 API 从维基百科页面的特定部分提取数据?

问题描述

我想从维基百科中提取蔬菜/水果的营养部分,并想在我的 android 应用程序中显示它。

我正在拍摄图片右侧的桌子

这是我到目前为止所得到的..

提取“香蕉”的营养部分

https://en.wikipedia.org/w/api.php?action=parse&page=banana&prop=wikitext§ion=23&format=json

但我不知道如何从我从上面的链接获得的数据中过滤掉这个表(上图右侧的表)。解析这些数据时我必须在我的代码中弄清楚还是我必须对 url 做一些事情?

谁能帮我做到这一点?

标签: androidjsonmediawiki-api

解决方案


Yeah, you'll have to do that yourself. You can use https://en.wikipedia.org/api/rest_v1/page/mobile-sections/Banana which is a little easier to use (OTOH it's more internally focused and so less stable) and does remove certain parts of the HTML, but you'd still have to deal with the table. Or you can try https://en.wikipedia.org/api/rest_v1/page/html/Banana which uses the next-generation HTML renderer and has more metadata in the HTML so it's maybe easier to transform, but you'd still have to do the transformation yourself.


推荐阅读