I want to integrate wikipedia in my iOS App (is it related to the mediawiki ?)

If so, I would like to know how I would tell wikipedia to give me an article about the o2 arena london (it is a one venue of London city) for example.

What would the url be for this example ?

I have searched in google and i have found this URL:

http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=o2%20arena%20london&rvprop=content&format=json&rvsection=0&rvparse=1

But this is not providing any data.

Is there any other URL ?

有帮助吗?

解决方案

Wikipedia runs on MediaWiki (plus some customizations which are also available), so the answer to your first question is "Yes".

First you need to use the OpenSearch API to find which pages contain the information you want. Searching for o2 arena london is the following URL:

https://en.wikipedia.org/w/api.php?action=opensearch&search=o2+arena+london&format=jsonfm

which gives the following results:

[
    "o2 arena london",
    [
        "O2 Arena London"
    ]
]

Using these results we can ask Wikipedia to return the HTML of the page. Here, the page "O2 Arena London" is a redirect to "O2 Arena (London)", so we need to ask Wikipedia to resolve the redirects and give us the final page. This is done using action=parse:

https://en.wikipedia.org/w/api.php?action=parse&redirects=1&page=O2+Arena+London&format=jsonfm

Which gives the following (shortened) results:

{
    "parse": {
        "title": "The O2 Arena",
        "revid": 578231031,
        "redirects": [
            {
                "from": "O2 Arena London",
                "to": "The O2 Arena"
            }
        ],
    "text": {
        "*": "<div class=\"dablink\">This article is about the indoor arena located in
             London.  For other uses, see <a href=\"/wiki/O2_Arena_(disambiguation)\"
             title=\"O2 Arena (disambiguation)\" class=\"mw-redirect\">O2 Arena</a>.

...

You can display the result, but it may look weird without the CSS styling of Wikipedia.

Note, also, that if you want actual JSON, you would use format=json instead of format=jsonfm.

其他提示

If you don't want to parse the wikipedia api output, why not

http://en.wikipedia.org/w/index.php?search=O2+arena+london

You just search for the words separated by +.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top