【发布时间】:2023-03-20 07:39:01
【问题描述】:
我在 scrapy 的帮助下收集了一些课程/课程,但它似乎只产生列表的 last 元素。
这是有问题的代码:
def parse_course_list(self, response):
""" Scrape list of lessons for each course """
lessons = response.css('ul.lessons-list a')
for lesson in lessons:
title = lesson.xpath("text()").extract_first().strip()
link = lesson.xpath("@href").extract_first().strip()
url = response.urljoin(link)
item = response.meta['item']
item['Lesson'] = title
item['URL'] = link
yield scrapy.Request(url, \
callback=self.parse_lesson,
meta={'item': item} \
)
所以基本上我正在收集课程并产生对详细信息页面的请求。但是,parse_lesson 函数中的教训总是相同的。
我在这里完全遗漏了什么吗?
【问题讨论】:
标签: python scrapy scrapy-spider