I'm trying to import this table from a wikipedia page containing the list of lunar missions into a Mathematica as an Association. Here, I'm trying to use the new WikipediaData function, but it doesn't seem to work.

WikipediaData["PageID" -> "656253283", "ArticleWikicode"]
  • $\begingroup$ When I use your code, it doesn't work but WikipediaData["List of missions to the Moon", "ArticleWikicode"] works fine. $\endgroup$ – Mahdi May 6 '15 at 17:15
  • $\begingroup$ Oh PageID is wrong, the correct one is 38293476. $\endgroup$ – Mahdi May 6 '15 at 17:17
  • 1
    $\begingroup$ You can alwars just use Import : Import["http://en.wikipedia.org/wiki/List_of_missions_to_the_Moon", {"HTML", "Source"}] . ( WikipediaData doesn't work for me either by the way ) $\endgroup$ – george2079 May 6 '15 at 17:45
  • 1
    $\begingroup$ This package could be used. The third example in that post is actually a table on Wikipedia. $\endgroup$ – C. E. May 7 '15 at 0:22
  • 1
    $\begingroup$ The function you are using is not going to work because that's not the PageID of the article you are trying to import. The correct one is 38293476, so, WikipediaData["PageID" -> "38293476", "ArticleWikicode"] works fine. But as Mahdi said, you can also use the actual title as in WikipediaData["List of missions to the Moon", "ArticleWikicode"] $\endgroup$ – xtian777x Aug 27 '15 at 3:57

As george2079 said, you can use Import:

text = Import["https://en.wikipedia.org/wiki/List_of_missions_to_the_Moon", "Data"];

and then naively because table has 7 columns:

table = Cases[text, {_, _, _,_, _, _, _}, ∞];

But you need to do some clean-up afterwards!


my stab at it..

 source = Import[
            {"HTML", "Source"}];
 tstart = StringPosition[source, 
        "<table class=\"wikitable sortable\"" ][[1, 1]];
 tend = Select[ 
          StringPosition[source, "</table>"] , #[[1]] > tstart & ][[1, 2]];
 tabledata = 
          StringTake[ source , {tstart, tend} ], {"html", "Data"}];

If there are more elegant ways of parsing html I'd like to see..

By the way WikipediaData gives me these sorts of errors no matter what I try:

" ServiceObject::noget: The parameter Wikicode is not available for the service Wikipedia. >> "


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.