Using Wikia API

3.2k views Asked by At

I am trying to access the X-men API on wikia, to try and extract the name and image of each character, to then be used on a SPA using javascript.

This is the link too the page on the wiki: http://x-men.wikia.com/wiki/Category:Characters

I cannot for the life of me figure out how to access the API. It doesn't seem to be RESFTful, and that's all I have any experience in.

Has anyone used the Wikia API successfully before? I can get some articles and such, but nothing useful.

(The documentation is shocking, been searching around for hours.)

1

There are 1 answers

0
Gio Bact On

Probably you have already found a solution, but I think you should write something like this:

import requests

xmen_url = "http://x-men.wikia.com/api/v1/Articles/List?expand=1&category=Characters&limit=10000"
r = requests.get(xmen_url)
response = r.json()
# print response
a = 0
for item in response['items']:
    a += 1
    print("{}\t{}\t({})".format(str(a),item['title'].encode(encoding='utf-8'),item['id']))

This will print a list of all the articles of the category Characters (I think there also some subcategories, you should check). If you want to take a deeper look at the json file you can uncomment the commented code.

Hope it helps.