JPC JPC - 4 months ago 52
Python Question

python beautiful soup how to json decode to dict

I'm new to beautifulsoup in python and I"m trying to extract dict from beatifulsoup

I use beautifulsoup to extract json and got my beautifulsoup.beautifulsoup variable

soup


I"m trying to get value out of
soup
, but when I do
result = soup.findAll("bill")
I got an empty list
[]
. How can I extract soup to get dict result of

{u'congress': 113,
u'number': 325,
u'title': u'A bill to ensure the complete and timely payment of the obligations of the United States Government until May 19, 2013, and for other purposes.',
u'type': u'hr'}


print type(soup)
print soup


=> result below

BeautifulSoup.BeautifulSoup

{
"bill": {
"congress": 113,
"number": 325,
"title": "A bill to ensure the complete and timely payment of the obligations of the United States Government until May 19, 2013, and for other purposes.",
"type": "hr"
},
"category": "passage",
"chamber": "s"
}





UPDATE

Here is how I got
soup
:

from BeautifulSoup import BeautifulSoup

import urllib2
url = urllib2.urlopen("https://www.govtrack.us/data/congress/113/votes/2013/s11/data.json")
content = url.read()
soup = BeautifulSoup(content)

Answer

Not very familiar with BeautifulSoup but if you just need to decode JSON

import json

newDictionary=json.loads(str(soup))