Reputation: 9157
I have a desire for a functionality in my app that lists plug sizes for different countries, and I found a nice wikipedia page that has this data:
If you scroll down you can see that the data is presented into a table. Since there is no Wikipedia API, I have to insert the data into a PLIST right? Is there another way to do this? How can I parse these tables into a dictionary or an array?
Upvotes: 1
Views: 354
Reputation: 12538
I have written a Wikipedia API Wrapper for Objective-C there you can get the html source of this wikipedia entry. With a DOM Parser you can find the table and loop over the entries and write it into a dictionary.
Unfortunately the table you need doesn't have an id. But you could search for one of the header words in the table step out one element and get the table.
https://github.com/prine/WikiApiObjectiveC
I just checked. These are the only four lines you need to fetch the html source of your desired article.
WikipediaHelper *wikiHelper = [[WikipediaHelper alloc] init];
wikiHelper.apiUrl = @"http://en.wikipedia.org";
NSString *searchWord = @"Mains_electricity_by_country";
NSString *htmlSource = [wikiHelper getWikipediaHTMLPage:searchWord];
Upvotes: 2
Reputation: 25632
The easiest way I can think of is copying the data and pasting it into your editor of choice.
Then use a combination of column editing, searching and replacing. I tend to use TextWrangler for that, which supports regex search and replace.
It's a one time job, and the number of lines is limited, so the solution probably doesn't need to be perfect - just good and convenient enough.
Upvotes: 1