Skip to content

Instantly share code, notes, and snippets.

@alxarch
Last active November 10, 2015 12:48
Show Gist options
  • Save alxarch/f3c094ae750938585f66 to your computer and use it in GitHub Desktop.
Save alxarch/f3c094ae750938585f66 to your computer and use it in GitHub Desktop.
Fetch mnc mcc data from wikipedia
declare option output:method "json";
let $page := doc("https://en.wikipedia.org/wiki/Mobile_country_code")
return
<json type="array">
{
for $h4 in $page//div[@id="bodyContent"]//h4
let $country-code := $h4/span[@id]/text()[last()]
let $rows := head($h4/following::table)/tr[td]
for $row in $rows
return <_ type="object">
<country>{replace($country-code, '.*- (.*)$', '$1')}</country>
<mcc>{$row/td[1]/text()}</mcc>
<mnc>{$row/td[2]/text()}</mnc>
<carrier>{$row/td[3]/data()}</carrier>
<company>{$row/td[4]/data()}</company>
</_>
}
</json>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment