作者helpking (帮王)
看板Python
标题Re: [问题] 爬虫表格的问题
时间Tue Aug 8 01:02:47 2017
※ 引述《ptoyhawinf (沉睡的毛利小五郎)》之铭言:
: 各位前辈好
: 小弟最近试着爬一些设备端的网页,想取得设备目前运作状态
: (snmp竟然没办法取得我想要的资讯)
: 试着用bs及pyquery来实作
: 但在table这卡关,希望有经验的前辈可以解惑一下
: html如下
: <table>
: <thead>
: <tr>
: <th>
: 栏位1</th>
: <th>
: 栏位2</th>
: <th>栏位3</th>
: <th>栏位4</th>
: <th>栏位5</th>
: <th>
: 栏位6</th>
: </tr>
: </thead>
: <tbody>
: <tr>
: <td rowspan="2">
: AB</td>
: <th>a0</th>
: <td class="bold green_border">a1<br></td>
: <td class="grey">a2</td>
: <td class="grey">a3</td>
: <td rowspan="2">ab4</td>
: </tr>
: <tr>
: <th>b0<br></th>
: <td class="bold">b1</td>
: <td class="grey">b2<br></td>
: <td class="grey">b3</td>
: </tr>
: <tr>
: <td rowspan="2">
: CD</td>
: <th>c0</th>
: <td class="bold">c1</td>
: <td class="grey">c2</td>
: <td class="grey">c3</td>
: <td rowspan="2">cd4</td>
: </tr>
: <tr>
: <th>d0<br></th>
: <td class="bold green_border">d1</td>
: <td class="grey">d2</td>
: <td class="grey">d3</td>
: </tr>
: </tbody>
: </table>
: 大致上,是要取得class = green_border的值,但也要取得它前後的一些栏位
: 但因为有的td rowspan =2,所以不管是直接filter green_border,再往前後取得值
: 或是取得tr後,再find,好像都拿不到rowspan的值
: 比如我要找的值是d1(栏位3),但我要怎麽拿到CD(栏位1)或cd4(栏位6)的值呢?
: 麻烦有经验的前辈指导一下,谢谢你们了。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 42.73.229.169
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1502125368.A.650.html
1F:→ hoho8: 没有内容?? 08/08 04:12