有一个html,它看起来像:
<html>
<head></head>
<body>
<div>
<h5 id="ca1">
<span>text</span>
<strong>text</strong>
<label>text</label>
</h5>
<div>
<h5 id = "ca2">
</h5>
<div id = "ca2body">
<table>
<tbody>
<tr>
<th><span>text</span></th>
<td>sth here</td>
<th><span>text</span></th>
<td>
<label></label>
text that i don't need
<label></label>
text that i don't need
<label></label>
text that i don't need
</td>
<script>
jQuery('#g2c4').change(function(){
if(jQuery('#g2c4').prop("checked")){
jQuery('#g2c4Span').show();
jQuery('.G2d').show();
}else{
jQuery('#g2c4Span').hide();
jQuery('.G2d').hide();
jQuery.each(jQuery('.chk_g2d'), function( index, item ) {
jQuery(item).prop('checked',false).change();
});
}
});
</script>
</tr>
<tr>
<th><span>text</span></th>
<td></td>
<th><span>text</span></th>
<td>
</td>
</tr>
<tr>TheSame</tr>
<tr>TheSame</tr>
<tr>TheSame</tr>
</tbody>
</table>
</div>
<h5 id = "ca3">
</h5>
<div id = "ca3body">
<table>
<tbody>
<tr>
<th><span>text</span></th>
<td></td>
<th><span>text</span></th>
<td></td>
</tr>
<tr>
<th><span>text</span></th>
<td></td>
<th><span>text</span></th>
<td></td>
</tr>
<tr>TheSame</tr>
<tr>TheSame</tr>
<tr>TheSame</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
我想得到文本:“sth here”所有父母标签名称。我需要让他们连接到一个词。就像:html_body_div_table_tbody_tr_td
我应该怎么做?
最后,我想制作一个 Json 文档。
[
{
"html_body_div_table_tbody_tr_th_span":"text",
"html_body_div_table_tbody_tr_td":""
}
]
我会尽量让它们成为字典,并使用字典的键和键值来做。做起来够容易吗?