Uma*_*air 4 css python xpath scrapy python-2.7
我正在尝试解析此 HTML。
<table id="ctl00_LeftColumnMiddle_Table1" border="0">
<tbody>
<tr>
<td>
<table border="0">
<tbody>
<tr>
<td >Contractor Name</td><td>UNITED RENTALS HIGHWAY TECHNOLOGIES INC</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td><table border="0">
<tbody>
<tr>
<td >Contractor Name</td><td>UNITED RENTALS NORTHWEST INC</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
它有几个TR,每个#ctl00_LeftColumnMiddle_Table1都有一个table内部tr
我想处理每条记录(实际上是一个 TR),然后处理每条记录的详细信息。
我试过这些选择器/Xpaths。
Selector(response).xpath('//*[@id="ctl00_LeftColumnMiddle_Table1"]/tbody/tr')
Run Code Online (Sandbox Code Playgroud)
和
Selector(response).css('#ctl00_LeftColumnMiddle_Table1 > tbody >tr')
Run Code Online (Sandbox Code Playgroud)
但这不会返回任何结果。
但如果我这样做
Selector(response).css('#ctl00_LeftColumnMiddle_Table1 tr')
Run Code Online (Sandbox Code Playgroud)
但是这个表达式也选择了内部trs with Contractor Nametoo。
这是 Scrapy 中的错误吗?
如果是,有没有其他方法可以按照我想要的方式处理记录?
我做到了
Selector(response).xpath('//*[@id="ctl00_LeftColumnMiddle_Table1"]/tr')
Run Code Online (Sandbox Code Playgroud)
或者
Selector(response).css('#ctl00_LeftColumnMiddle_Table1 > tr')
Run Code Online (Sandbox Code Playgroud)
这是因为tbodyFirefox 和 Chrome 等浏览器会自动添加标签。
但随着Scrapy刮的时候,tbody是不存在的responseHTML。
| 归档时间: |
|
| 查看次数: |
2630 次 |
| 最近记录: |