'parsing table of emergency numbers from wikipedia

I am trying to write a javascript snippet to parse the data from the tables on this page: https://en.wikipedia.org/wiki/List_of_emergency_telephone_numbers

I found dbpedia which seems promising, but it seems as if their system ignores the tables: https://dbpedia.org/describe/?url=http%3A%2F%2Fdbpedia.org%2Fresource%2FList_of_emergency_telephone_numbers&invfp=IFP_OFF&sas=SAME_AS_OFF&sid=868

Does anybody know an alternative way to parse the data.



Solution 1:[1]

python to the rescue, I couldn't find an easy way to do this in javascript but in python.

I found an easier to parse table here: https://www.adducation.info/general-knowledge-travel-and-transport/emergency-numbers/ But it is still an html table and I want to use it in Javascript, so JSON is easier. This code solves my problem:

import pandas as pd
data = pd.read_html("emergency_numbers.html")[0]
json_data = data.to_json(orient="records")
with open("emergency_numbers.json", "w") as f:
    f.write(json_data)

result is:

  [ { 'Country / Territory'            : '\ud83c\udde6\ud83c\uddeb Afghanistan'
    , '\u260e Emergency'               : null
    , '\u260e Police'                  : '119'
    , '\u260e Ambulance'               : '119, 102'
    , '\u260e Fire'                    : '112, 119'
    , 'Group'                          : 'Asia'
    , 'Calling codes'                  : '+93'
    , 'Local emergency numbers & info' : 'You can dial 020 112 from mobile but only in Kabul.'
    } 
  , { 'Country / Territory'            : '\ud83c\udde6\ud83c\uddf1 Albania'
    , '\u260e Emergency'               : null
    , '\u260e Police'                  : '129'
    , '\u260e Ambulance'               : '127'
    , '\u260e Fire'                    : '128'
    , 'Group'                          : 'Europe'
    , 'Calling codes'                  : '+355'
    , 'Local emergency numbers & info' : null
    } 
  , { 'Country / Territory'            : '\ud83c\udde9\ud83c\uddff Algeria'
    , '\u260e Emergency'               : null
    , '\u260e Police'                  : '17'
    , '\u260e Ambulance'               : '14'
    , '\u260e Fire'                    : '14'
    , 'Group'                          : 'Africa'
    , 'Calling codes'                  : '+213'
    , 'Local emergency numbers & info' : 'Dial 1548 for tourist police.'
    } 
  , { 'Country / Territory'            : '\ud83c\udde6\ud83c\uddf8 American Samoa'
    , '\u260e Emergency'               : '911'
    , '\u260e Police'                  : null
    , '\u260e Ambulance'               : null
    , '\u260e 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mister Jojo