我是 Python 中 BeautifulSoup 的新手,我正在尝试dict
从 BeautifulSoup 中提取。
我使用 BeautifulSoup 提取 JSON 并获得beautifulsoup.beautifulsoup
variable soup
。
我试图从中获取值soup
,但是当我这样做时,result = soup.findAll("bill")
我得到一个空列表[]
。如何提取汤以获得dict
以下结果:
{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
=>结果如下
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"
}
更新
这是我得到的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)