1

I've searched far and wide for this and unfortunately haven't been able to find an answer. I'm trying to fetch table elements from Wikipedia pages using the Wikipedia API and JavaScript/jQuery. For example, take the page below:

https://en.wikipedia.org/wiki/2017_NFL_Draft

If I want to be able to use the API to fetch just one cell of the table (eg round 1, pick #7, or all players drafted from UCLA) is there a way to do this? Because each page of these is the same, think this will be easy to do one call across pages (just need to increment the url by 1), but I haven't had any luck using the API to fetch anything except for a section.

I tried the test call which shows me the table:

https://en.wikipedia.org/w/api.php?action=parse&page=2017_NFL_Draft&section=2&prop=text

And I see the specific elements I'd like to grab but can't figure out how. Is there anyway to do this? Would I be better off just copying/pasting the data in excel and putting it in a form I want?

Thanks for all of your help!

2

1 Answer 1

1

I believe this is what you are looking for. I am pulling in the main table . You can refine your element queries inside my $table object

var params = {
  origin: '*',
  action: 'parse',
  page: '2017_NFL_Draft',
  section: 2,
  prop: 'text',
  format: 'json'
};

$.getJSON('https://en.wikipedia.org/w/api.php', params).then(res => {
  var $table = $(res.parse.text['*']).find('table').eq(3)
  $('body').append($table)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

4 Comments

Wow this is great! Thanks so much...just what I need to get me started. One question...what does the "origin" here denote with the " * "? Unclear from the wiki documentation.
Oh that is a requirement for CORS from mediawiki.org/wiki/Manual:CORS. Is a pain to track down. I also had to do a search on this site and found that using * as origin works
Suggest you start a new question for that and in that question provided the source html
Thanks but think I figured it out actually, or rather, am close to figuring it out (so I deleted the question)! Appreciate your help here, absolutely huge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.