1

Possible Duplicate:
dbpedia country profile query

I would like to get the country information that is listed on the right of a page with the wikipedia api. The documentation is chaotic so any help is appreciated.

Community
  • 1
  • 1
cosapostolo
  • 1,099
  • 2
  • 7
  • 9

1 Answers1

2

That will be difficult, because county information is inserted ad-hoc in templates. For example, at http://en.wikipedia.org/wiki/Dresden the county is probably inserted by "Infobox German location" template. If you need to get this programatically for articles about places, you can try one of two ways:

  • getting it via geolocation coordinates (coordinates may also be difficult to parse out from the wikitext, but in the worst case you can get it from geohack link in generated HTML)
  • looking on the categories given page is in, and going up to find categories that correspond to individual countries (but this might not work properly in all cases, since the categories might be a bit chaotic)
che
  • 12,097
  • 7
  • 42
  • 71
  • thank you for the reply, so if I wanted some information that is same for all pages, eg: Official language, how do I extract if from a page like this? http://en.wikipedia.org/w/api.php?format=xml&action=query&titles=italy&prop=revisions&rvprop=content – cosapostolo Oct 23 '12 at 13:41
  • I'm afraid you'd have to parse wikitext source code and get the arguments for "Infobox country" template. See for yourself it looks in the source: http://en.wikipedia.org/w/index.php?title=Germany&action=edit – che Oct 23 '12 at 13:44
  • but how do I do that with php? do I do that with regular expression or is there an easier way? – cosapostolo Oct 23 '12 at 13:47
  • Regular expression might be one option, the other would be looking at sources at http://stackoverflow.com/a/4201619/7806 -- especially DBPedia seems promising – che Oct 23 '12 at 13:53
  • can you show me an example of a query with DBPedia? – cosapostolo Oct 23 '12 at 14:09