Skip to content

Instantly share code, notes, and snippets.

@Zylvian
Created April 13, 2019 00:10
Show Gist options
  • Save Zylvian/8c16c5c3b04ddb8c568798db1968e03c to your computer and use it in GitHub Desktop.
Save Zylvian/8c16c5c3b04ddb8c568798db1968e03c to your computer and use it in GitHub Desktop.
startlink = 'https://onepiece.fandom.com/api.php?format=json&action=query&'
test_name = "Monkey D. Luffy"
fetch_json = requests.get(startlink + 'generator=allpages&gapfrom=' + test_name + '&prop=info&inprop=url').json()
print(fetch_json)
# Gets all pages
all_pages = fetch_json['query']['pages']
# Gets first page
first_page = next(iter(all_pages.values()))
# Gets first url
first_title = first_page["title"]
first_url = first_page["fullurl"]
# THIS IS THE URL WE NEED AT LEAST
print(first_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment