Ознакомьтесь со следующей реализацией, которая позволит вам разобрать название должности и их названия компаний с этого сайта.То, как вы определили xpath, подвержено ошибкам.Однако я изменил их, чтобы они могли работать правильно.Попробуйте:
import scrapy
class remoteworkhub(scrapy.Spider):
name = 'remoteworkhub'
start_urls = ['https://jobs.remoteworkhub.com']
def parse(self, response):
for job_link in response.xpath("//*[contains(@class,'job-listing')]//*[@class='jobList-title']/@href").extract():
Url = response.urljoin(job_link)
yield scrapy.Request(Url, callback=self.parsejobpage)
def parsejobpage(self, response):
d = {}
d['title'] = response.xpath("//*[@class='jobDetail-headerIntro']/h1/text()").get()
d['company'] = response.xpath("//*[@class='jobDetail-headerIntro']//strong//text()").get()
yield d
Это вывод, который я вижу в консоли, если я использую print вместо yield:
{'title': 'Sr Full Stack Developer, Node/React - Remote', 'company': 'Clevertech'}
{'title': 'Subject Matter Expert, Customer Experience - Remote', 'company': 'Qualtrics'}
{'title': 'Employee Experience Enterprise Account Executive - Academic and Government - Remote', 'company': 'Qualtrics'}
{'title': 'Senior Solutions Consultant, Brand Experience - Remote', 'company': 'Qualtrics'}
{'title': 'Data Analyst - Remote', 'company': 'Railsware'}
{'title': 'Recruitment Manager - Remote', 'company': 'Railsware'}