0

Hi i am working on a site which fetches random articles from Wikipedia and displays them on my site. The problem is i have no idea how to retrieve those articles. Documentation is also of no help. Can someone advice me how to approach it? Can we use api's? I am using PHP+HTML.

Anidh Singh
  • 302
  • 2
  • 7
  • 19
  • 2
    Welcome. Please read [how to ask](http://stackoverflow.com/help/how-to-ask) and what is in scope at Stack Overflow. – micstr Jun 21 '16 at 07:06
  • 1
    The link to a random article on Wikipedia is `https://en.wikipedia.org/wiki/Special:Random`. You could just make an AJAX call to that page, and then place the contents of the return data's `` tag where you want it. – Ben Hillier Jun 21 '16 at 07:09

2 Answers2

1

Very recently there's been a new API endpoint released.

It gives you the random article in a requested format, which could be just a title, html, summary, mobile-sections or mobile-sections-lead (special formats optimised for use in mobile apps). Also it's possible to get a set of articles related to a random article.

Also this is a 'smart random' - it filters out articles without content, special pages etc, so you are a bit more certain to get a good random article using this API endpoint, then a special page.

Petr
  • 5,999
  • 2
  • 19
  • 25
0

Just use this link: https://en.wikipedia.org/wiki/Special:Random It will show you a random article. You can try to in include it on your site with php or as iframe.

  • What i want is that the whole article is displayed "as is" on my site. – Anidh Singh Jun 21 '16 at 07:22
  • You mean the article without wikipedias menu-bar? Then you could try something like this: http://stackoverflow.com/questions/4101770/load-content-of-a-div-on-another-page –  Jun 21 '16 at 07:28
  • Thanks but that is implemented through JQuery isn't there any PHP workaround? – Anidh Singh Jun 21 '16 at 07:38
  • I can't imagine how to do this with php but you could try to play around with the `include("")` method. –  Jun 21 '16 at 07:44
  • Okay no problem mate.. Hopefully someone else finds a workaround – Anidh Singh Jun 21 '16 at 07:48