This goes out to all the Mathematica experts - I'm hoping to get some helpful comments, ideas or code for that matter.

In my attempts to maximize learning efficiency I had the idea to create an (undirected) graph of Wikipedia hyperlinks of a specific topic (e.g. probability theory).

This then could be used to identify central nodes/topics which are necessary (i.e. highly connected to other nodes) to understand the rest of the topic more easily, instead of more or less arbitrarily browsing through Wikipedia. For example would it be more efficient to start from a central node/topic since other topics are based on an understanding of this node/topic.

I have trouble reading out the hyperlinks from Wikipedia (e.g. up to a some depth) and I don't even know how to start with the graph, so any help (or examples) to get me started would be appreciated.


2 Answers 2


Yep, as @Sjoerd mentions in the comments, 10.1 includes the WikipediaData functionality. You can use like this:

links = WikipediaData["Mathematica", "BacklinksRules", "MaxLevelItems" -> 10, "MaxLevel" -> 2]
Graph[links, VertexLabels -> Placed["Name", Tooltip], VertexStyle -> {"Mathematica" -> Red}]

enter image description here

  • $\begingroup$ Unfortunately only have Mathematica 9, but now I need M10 :D..thanks! $\endgroup$
    – holistic
    Jun 5, 2015 at 14:26
  • $\begingroup$ This code no longer works in Vers. 14.0. It appears that links variable is not constructed in a way that passes the edge list to graph in a way that it accepts to generate the graph. $\endgroup$ Apr 5 at 3:16

If you wanted to do this same kind of parsing for a website for which a built-in function was not available, you could read in the contents of the web page (using URLFetch) and then search this for links, which usually start with "href". For example

str = "https://en.wikipedia.org/wiki/Main_Page";
q = URLFetch[str];
ind = Position[StringPosition[StringSplit[q], "href"], {1, 4}][[All, 1]];
StringSplit[q][[#]] & /@ ind

creates a long list showing all the links on the page indicated in str, in this case, on the main page of wikipedia.

  • $\begingroup$ For external links, Import["https://en.wikipedia.org/wiki/Main_Page" , "Hyperlinks"] should work too $\endgroup$
    – Max Coplan
    Jan 7, 2019 at 20:25

Your Answer

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

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