当所有数据似乎都在一个没有结构的项目中时使用scrapy

问题描述 投票:0回答:1

我正在抓取这个网站,理想情况下将每篇论文的信息作为单独的条目获取。使用 scrapy shell 和“查看页面源代码”进行探索后,所有信息似乎都在一项中

如何使用 scrapy 和 xpaths 获取此特定网站的每篇论文的信息?

这是我尝试选择一篇论文的xpath。

//*[@id="content"]/div[3]/div[1]/div[3]/div/div[2]/div[2]/ul/li[1]

scrapy
1个回答
0
投票

你应该像这样使用 XPath

//div[@class="result-list"]/ul/li
在它之后,您应该使用所有子 xpath(以循环为例)和“。”字首。示例:

for children_node in response.xpath('//div[@class="result-list"]/ul/li'):
    children_node.xpath('.//h5/text()').get()  # get h5 title text

要获得有关 XPath 的更多理论和实践,您可以使用以下来源: https://www.w3schools.com/xml/xpath_syntax.asp https://www.freeformatter.com/xpath-tester.html

© www.soinside.com 2019 - 2024. All rights reserved.