我有一段代码,我试图下载这些文件,但是循环只打印了第一个元素。
从urllib导入scrapy。解析导入urljoin
类简单蜘蛛(小蜘蛛):新冠肺炎病例报告网站首页
def parse(self, response):
for book in response.xpath('//*[@id="main-content"]/div/main/div[2]/ol'):
title= response.xpath('/li[3]/article/h3/a/text()').get()
link = urljoin(
'https://jmedicalcasereports.biomedcentral.com/',response.xpath('/li[3]/article/ul/li[2]/a/@href').get()
)
yield {
'Title':title,
'file_urls':[link]
}
我使用了css,然后是xpath,问题是循环代码。
1条答案
按热度按时间cngwdvgl1#
首先,在代码的第三行中,response可以更改为title
第二,在你的第二行,你给予了一个不正确的xpath。所以结果是不正确的。这是我的代码。希望这能帮助你。
回应是: