【发布时间】:2020-03-08 22:59:20
【问题描述】:
我构建了一个抓取工具来为我的项目从 3 个站点中提取文本。我想为 3 个站点使用一个蜘蛛。 2 个网站的内容采用这种结构:
<div id="site1">
<p> this is a test </p>
</div>
<div id="site2">
<p> this is a test </p>
</div>
还有一个:
<div class="site3">
<p> <span> this is a test </span> </p>
</div>
我可以使用以下方法从 2 个站点中提取文本:
response.xpath('//div[@id="site1" or @id="site2" or @class="site3"]//p/text()').extract()
如何修改此代码以从 site3 中提取文本?
【问题讨论】:
标签: python html xpath web-scraping scrapy