我想提取每个 div class="summary"
中的网页内容。
在每个 summary
div 中,我想提取 div 中每个类中的数据。
以下是我的片段。
questions = Selector(response).xpath('//div[@class="summary"]')
for question in questions:
item = StackItem()
# get the hyperlink of h3 text
item['title'] = question.xpath('a[@h3]/text()').extract()[0]
yield item
我应该如何在我的代码中编写 xpath 内容?
最佳答案
您的第二个 XPath 查找 a
元素,该元素是 div[@class="summary"]
的直接子元素并且具有属性 h3
,它在发布的 HTML 中不存在。
从 div
获取 h3
中的 a
元素的正确 XPath 如下:
h3/a/text()
关于python - Scrapy,如何提取h3内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37544295/