在Python

时间:2017-10-09 23:29:26

标签: python html json

我已经回顾了围绕HTML的可能解决方案到Python中的JSON解析,但无法确定正确的解决方案。

上下文

原型的一部分:我使用request.get()方法从第三方组织接收数据。响应是HTML 4.0(loose.dtd格式)。

问题陈述: 使用Json.dumps& file.write操作,我已将此响应保存到本地文件(期望它是JSON)。

但内容不会解析任何HTML代码(例如<thead><td>等。)

我需要将此HTML内容转换为JSON(或字典)。我想用它作为数据源。

观察: 我遇到过几个java代码片段,他们尝试手动解析。希望有一种最佳方式来实现这一目标。

示例回复

<thead>\r\n<tr>\r\n<th bgcolor=\"#eeeeff\">Number</th>\r\n<th
bgcolor=\"#eeeeff\">Volcano Name</th>\r\n<th
bgcolor=\"#eeeeff\">Country</th>\r\n<th bgcolor=\"#eeeeff\">Region</th>\r\n<th
bgcolor=\"#eeeeff\">Latitude</th>\r\n<th
bgcolor=\"#eeeeff\">Longitude</th>\r\n<th bgcolor=\"#eeeeff\">Elev</th>\r\n<th
bgcolor=\"#eeeeff\">Type</th>\r\n<th bgcolor=\"#eeeeff\">Status</th>\r\n<th
bgcolor=\"#eeeeff\"><a
href=\"\"OnClick=\"hold=window.open('/nndc/DescribeField.jsp?dataset=102557&s=77&field_name=HAZ.VOL_LOC_TSQP.TIME_ERUPT','commentsWindow','menubar=no,scrollbars=yes,resizable=yes,width=620,height=425,left=5,top=50');
hold.focus(); return false;\">Last
Known<br>Eruption</a></th>\r\n\r\n</tr>\r\n</thead>

<tr>\r\n<td
valign=\"top\">0803-001</td>\r\n<td valign=\"top\">Abu</td>\r\n<td valign=\"top\">Japan</td>\r\n<td valign=\"top\">Honshu-Japan</td>\r\n<td valign=\"top\">34.5</td>\r\n<td valign=\"top\">131.6</td>\r\n<td valign=\"top\">571</td>\r\n<td valign=\"top\">Shield volcano</td>\r\n<td valign=\"top\">Holocene</td>\r\n<td valign=\"top\">Unknown</td><tr>\r\n<td valign=\"top\">1505-096</td>\r\n<td valign=\"top\">Acamarachi</td>\r\n<td valign=\"top\">Chile</td>\r\n<td valign=\"top\">Chile-N</td>\r\n<td valign=\"top\">-23.3</td>\r\n<td>

0 个答案:

没有答案