我有这样的文件要用Python解析(从废弃开始):
some HTML and JS here...
SomeValue =
{
'calendar': [
{ 's0Date': new Date(2010, 9, 12),
'values': [
{ 's1Date': new Date(2010, 9, 17), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 18), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 19), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 20), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 21), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 22), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 23), 'price': 9900 }]
},
'data': [{
index: 0,
serviceClass: 'Economy',
prices: [9900, 320.43, 253.27],
eTicketing: true,
segments: [{
indexSegment: 0,
stopsCount: 1,
flights: [{
index: 0,
... and a lot of nested data and again HTML and JS...
我需要解析它并提取所有json数据。现在我使用regex和cleaning all'\n'和'\t'以及eval()函数将其转换为Python字典。。我真的不喜欢这个解决方案,尤其是eval()。但是我查看了beauthoulsoup和lxml,没有找到有助于解析它的东西。
你能为这个任务推荐比regex和eval()更好的方法吗?
页面示例:http://codepaste.ru/3830/
aarrghhh no regex dont use regex no regex no no nooooooo
使用
json
模块处理JSON数据:使用
^{pr2}$BeautifulSoup
或lxml
处理html页面的解析:如果您需要特定的帮助,您需要提供特定的数据,例如包含此数据的标记的类。例如,您可以
soup.findAll
脚本标记,然后剥离一些行以获取JSON,然后将其输入json.loads
。在相关问题 更多 >
编程相关推荐