2

I'm using wikipedia-api on Python (also known as wikipediaapi). This is the following code that I use:

import wikipediaapi

wiki_wiki = wikipediaapi.Wikipedia('en')

page = wiki_wiki.page('Special:Random')

title = page.title   

I'm expecting the output to be a random article name. How do I do this, or this repository didn't have anything for random articles?

weareblahs
  • 57
  • 7
  • Edited it to include the "import wikipediaapi" line in the original question so it should be right. The output that I got is just simply "Special:Random". – weareblahs Apr 24 '22 at 08:26
  • 1
    Is there anything in the docs of wikipedia api to suggest that should work? It's just a wrapper to the actual API, so why not use the API directly? https://stackoverflow.com/questions/33614492/wikipedia-api-get-random-pages has all the details – smartse Apr 25 '22 at 18:53

1 Answers1

0

Get a random article title

import requests
import json

req = requests.get("https://en.wikipedia.org/api/rest_v1/page/random/summary")
title = json.loads(req.content)["title"]
Rony Macfly
  • 210
  • 2
  • 4
  • 10