python - 获取表格中部分数据
大家讲道理
大家讲道理 2017-04-18 10:16:44
0
2
429

只获取广东这条信息,但是第二行在其他页面中可能就变成第三行了,求问怎么获取
<td class="op_trust_tdRight">广东</td>

<table width="100%;">
                        <tr>
                <td class="op_trust_tdLeft">执行法院:</td>
                <td class="op_trust_tdRight">福田区人民法院</td>
            </tr>
            <tr>
                <td class="op_trust_tdLeft">省份:</td>
                <td class="op_trust_tdRight">广东</td>
            </tr>
            <tr>
                <td class="op_trust_tdLeft">案号:</td>
                <td class="op_trust_tdRight">(2011)深福法执字第01854号</td>
            </tr>
           
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
刘奇

var table=document.getElementsByTagName("table");
var targetVal=table[0].rows[1].cells[1];

Peter_Zhu

One way is to find the cell in the province and then extract the data of the adjacent cells. I use pyquery to parse html. If you have written front-end jquery, you should be familiar with it.

from pyquery import PyQuery as pq
t='''<table width="100%;">
                        <tr>
                <td class="op_trust_tdLeft">执行法院:</td>
                <td class="op_trust_tdRight">福田区人民法院</td>
            </tr>
            <tr>
                <td class="op_trust_tdLeft">省份:</td>
                <td class="op_trust_tdRight">广东</td>
            </tr>
            <tr>
                <td class="op_trust_tdLeft">案号:</td>
                <td class="op_trust_tdRight">(2011)深福法执字第01854号</td>
            </tr>'''
p=pq(t)
print(p.find('.op_trust_tdLeft').filter(lambda i,this: pq(this).text() == '省份:').parent().find('.op_trust_tdRight').text())
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!