我有一个项目要从class-central.com抓取数据。如果您打开此网站并单击任一主题(例如,计算机科学),则将获得课程列表。在页面底部,有一个下一个按钮,显示更多的课程,并且一直持续到显示所有课程为止。我想刮所有的课程。
import scrapy
from ..items import ClasscentralItem
class ClassCentral(scrapy.Spider):
name = 'spidy'
start_urls = [
'https://www.classcentral.com/subject/cs'
]
def parse(self, response):
items = ClasscentralItem()
all_tr = response.css('#course-listing-tbody tr[itemscope]')
courses = response.css('.number-of-courses .text--bold::text')
for x in all_tr:
sub = response.css('.medium-up-head-1::text').extract()
course_name = x.css('.course-name .text--bold::text').get()
course_devloper = x.css('.uni-name::text').extract()
via = x.css('.text--italic::text').get()
duration = x.css('.icon-clock-charcoal::text').extract()
start_date = x.css('.medium-only-hidden::text').get()
rating = x.css('td:nth-child(4)').attrib['data-timestamp']
number_review = x.css('td#span#a::text').get()
items['subjectname'] = sub
items['course_name'] = course_name
items['course_devloper'] = course_devloper
items['via'] = via
items['duration'] = duration
items['start_date'] = start_date
items['rating'] = rating
items['number_review'] = number_review
yield items
我正在为抓取单击“下一步”按钮后显示的课程而苦恼。 另外,我无法在每门课程上都刮掉“复习次数” 。 这是我的代码,
请帮助。
(PS:我是一个初学者,所以请尝试使您的答案尽可能简单)