python - 使用 scrapy 抓取特定的表格元素

标签 python html web-scraping scrapy

我正在使用 scrapy 从特定 <td> 内的网站中抓取内容标签。本教程向我展示了如何下载所有数据——我只想要 <td> 中的数据。 。停下来!

示例通用表代码:

<table>
<tr>
<td>1,1</td>
<td>1,2</td>
</tr>
<tr>
<td>2,1</td>
<td>2,2</td>
</tr>
</table>

我不知道如何获取 2,2值。

提前致谢

最佳答案

使用 response.xpath()response.css() 快捷方式获取 table 中的最后一个 td 元素。示例:

response.xpath("//table//td[last()]/text()").extract_first()
response.xpath("//table//td/text()").extract()[-1]
response.css("table td::text").extract()[-1]

关于python - 使用 scrapy 抓取特定的表格元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36670918/

相关文章:

python - Django migrate 尝试连接到非默认数据库

python - 我怎样才能得到作为某个动词宾语的名词从句?

javascript - 选择 onchange 相同的值

html - 防止左右div边框出现水平滚动条

javascript - 打开弹出窗口后谷歌浏览器上出现奇怪的行,如何避免?

python - 使用漂亮的汤从 URL 中提取内容时如何设置 session cookie?

xpath - 从分布在不同 div 的列表中提取内容

python - 如何从 Python 中的文本文件导入矩阵

php - 是否有使用 Curl 而不是 file_get_contents 的 (PHP) Web 抓取框架?

python - Unicode Box Drawing 字符未在 Ruby 中打印