【发布时间】:2020-03-15 20:50:20
【问题描述】:
我尝试使用 scrapy 从表中获取测试或数据。但是表没有类。 structur HTML的部分是这样的:
<div class="content_e">
<div class="content-ranklist">
<div class="rank-title"><span><h1><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Beijing gourmet restaurant
</font></font></h1></span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Updated on November 20th</font></font>
</div>
<section class="ranklist-table">
<table>
<tbody>
<tr>
<th class="th-label-0">
<div><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Ranking</font></font>
</div>
</th>
</tr>
<tr>
<td class="td-rank">
<div class="td-div-1"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">1</font></font>
</div>
</td>
我试图用不同的方式解决问题。但是,我总是得到None 的[]。
我做的是这样的:
response.css('div.content-ranklist section.ranklist-table table').extract()
response.css('div.content-ranklist section.ranklist-table table tr td.td-shopName').extract()
response.css('//td[contains(@class, "td-shopName")]/text()').extract()
response.xpath("//table/tbody/tr//td[@class='td-shopName']//a[@class='J_shopName']").extract()
结果总是None 和[]
这是结果
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
[]
=-=-=-=-
``
i was try to get this class :
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/40x4o.png
【问题讨论】:
-
你想提取什么?
-
表格内的td
-
请显示示例输出
-
我在测试我的代码后用结果编辑了我的问题
-
我在问你这里的 html 源代码的预期输出!您要提取的文本!
标签: python html web-scraping scrapy tags