In [1]:
import mf2py

obj = mf2py.parse(url='http://localhost:3000/')


/usr/local/lib/python3.6/site-packages/bs4/__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 193 of the file /usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup(YOUR_MARKUP})

to this:

 BeautifulSoup(YOUR_MARKUP, "lxml")

  markup_type=markup_type))

In [5]:
obj.keys()


Out[5]:
dict_keys(['items', 'rels', 'rel-urls'])

In [12]:
items = obj['items']

items[0].keys()


Out[12]:
dict_keys(['type', 'properties'])

In [13]:
items[0]['type']


Out[13]:
['h-card']

In [14]:
items[0]['properties']


Out[14]:
{'name': ['Myles Braithwaite'],
 'note': ['Myles Braithwaite lives in Toronto where he runs a small consulting company called Monkey in your Soul (you should hire him). His interests range from photography to hiking. He is also interested in programming, music, snowboarding, and watching movies and television.'],
 'org': ['Monkey in your Soul',
  {'properties': {'name': ['Monkey in your Soul'],
    'url': ['https://monkeyinyoursoul.com/']},
   'type': ['h-card'],
   'value': 'Monkey in your Soul'},
  {'properties': {'name': ['Rotten Bananas'],
    'url': ['https://rottenbananas.ca/']},
   'type': ['h-card'],
   'value': 'Rotten Bananas'}],
 'url': ['https://twitter.com/mylesb',
  'https://myles.life/@me',
  'https://github.com/myles',
  'https://www.instagram.com/myles/',
  'https://linkedin.com/in/mylesbraithwaite/']}

In [16]:
obj.to_json()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-5976ddf36e02> in <module>()
----> 1 obj.to_json()

AttributeError: 'dict' object has no attribute 'to_json'

In [27]:
p = mf2py.Parser(url='http://localhost:3000/', html_parser='lxml')

h_card = p.to_dict(filter_by_type='h-card')[0]

h_card


Out[27]:
{'properties': {'name': ['Myles Braithwaite'],
  'note': ['Myles Braithwaite lives in Toronto where he runs a small consulting company called Monkey in your Soul (you should hire him). His interests range from photography to hiking. He is also interested in programming, music, snowboarding, and watching movies and television.'],
  'org': ['Monkey in your Soul',
   {'properties': {'name': ['Monkey in your Soul'],
     'url': ['https://monkeyinyoursoul.com/']},
    'type': ['h-card'],
    'value': 'Monkey in your Soul'},
   {'properties': {'name': ['Rotten Bananas'],
     'url': ['https://rottenbananas.ca/']},
    'type': ['h-card'],
    'value': 'Rotten Bananas'}],
  'url': ['https://twitter.com/mylesb',
   'https://myles.life/@me',
   'https://github.com/myles',
   'https://www.instagram.com/myles/',
   'https://linkedin.com/in/mylesbraithwaite/']},
 'type': ['h-card']}

In [ ]: