【发布时间】:2023-03-11 07:43:02
【问题描述】:
所以我被要求从网站上抓取所有工作详细信息,但是我的蜘蛛成功获取到下一页的链接,但只从第一个页面中提取数据
这是我的蜘蛛:
name = 'jobs'
allowed_domains = ['www.tanitjobs.com/jobs']
start_urls = ['https://www.tanitjobs.com/jobs']
def parse(self, response):
pass
all_jobs = response.css(".listing-item__jobs")
for job in all_jobs:
item = {
'jobname' : job.css("article.listing-item div.listing-item__title a::text").getall(),
"companyname" : job.css(".listing-item__info--item-company::text").extract(),
"city" : job.css(".listing-item__info--item-location::text").extract() ,
}
yield item
next_page = response.css(".pad_right_small a ::attr(href)").extract_first()
if next_page:
next_page = response.urljoin(next_page)
yield scrapy.Request(url=next_page, callback=self.parse)
This is the result that i got after running the spider
如果有人知道问题出在哪里,我真的需要你的帮助并提前感谢。
【问题讨论】:
-
我认为 a 和 ::attr(href) 之间的空格是错误的,您可能需要将链接设为绝对链接。
-
@pguardiario 这是绝对的,我只是使用 urljoin 来实现这一点
标签: python web-scraping pagination scrapy