【发布时间】:2015-07-26 16:27:40
【问题描述】:
我正在尝试从 这个网页,链接到网页 http://www.disastercenter.com/crime/uscrime.htm
我可以把它变成文本文件。但我想得到 Json 格式的响应。我如何在 python 中做到这一点。
这是我的代码:
import urllib
import re
from bs4 import BeautifulSoup
link = "http://www.disastercenter.com/crime/uscrime.htm"
f = urllib.urlopen(link)
myfile = f.read()
soup = BeautifulSoup(myfile)
soup1=soup.find('table', width="100%")
soup3=str(soup1)
result = re.sub("<.*?>", "", soup3)
print(result)
output=open("output.txt","w")
output.write(result)
output.close()
【问题讨论】:
-
您的结果与 json 相差甚远,您期望输出什么?
-
将数据放入由lists/dicts/strs/numbers组成的有用Python数据结构中,然后使用json模块。
-
标签: python json python-2.7