Sam Salim
Sam Salim

Reputation: 2372

Is there any API function to query wikipedia api by website url?

I'm trying to implement something similar to query wikipedia like google is doing. To explain better; for example if we search "youtube.com" in google, google displays some information on the right.

enter image description here

But couldn't find the right wikipedia API function to get these details. It's important to search for the website url but not for a general topic like "youtube". Because what I need is exactly to get some details about the website but not for the company only.

I've found a couple of API functions but still couldn't find the right one.

This one for example is returning the original wikipedia link.

https://en.wikipedia.org/w/api.php?action=opensearch&search=**google.com**&limit=1&format=json

The response is:

["google.com",["GOOGLE.com"],[""],["https://en.wikipedia.org/wiki/GOOGLE.com"]]

And this one is not exactly returning what I need and also for some other websites it's just returning different results for different websites.

https://en.wikipedia.org/w/api.php?action=query&format=xml&list=search&srprop=snippet&srsearch=google.com

enter image description here

Any suggestion please.

Upvotes: 0

Views: 272

Answers (1)

Sam Salim
Sam Salim

Reputation: 2372

The solution for me is using 2 APIs. First checking the url exists here;

https://en.wikipedia.org/w/api.php?action=opensearch&search=youtube.com&limit=1&namespace=0&format=jsonfm

and if the last node is not empty then;

https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=youtube.com&exintro=&exsentences=55&explaintext=&redirects=&formatversion=2

exsentences is key on this function.

Hope it helps someone else.

Upvotes: 1

Related Questions