# -*- coding: utf-8 -*-
import scrapy
class SearchSpider(scrapy.Spider):
name = 'search'
allowed_domains = ['www.indeed.com/']
start_urls = ['https://www.indeed.com/jobs?q=data%20analyst&l=united%20states']
def parse(self, response):
listings = response.xpath('//*[@data-tn-component="organicJob"]')
for listing in listings:
title = listing.xpath('.//a[@data-tn-element="jobTitle"]/@title').extract_first()
link = listing.xpath('.//h2[@class="title"]//a/@href').extract_first()
company = listing.xpath('normalize-space(.//span[@class="company"]//a/text())').extract_first()
yield {'title':title,
'link':link,
'company':company}
next_page = response.xpath('//ul[@class="pagination-list"]//a/@href').extract_first()
if next_page:
yield scrapy.Request(response.urljoin(next_page),callback=self.parse)
我正在尝试为所有确实存在的页面中的每个职位发布提取所有职位名称和公司。但是,我被困在一点,因为确实页面上的前进按钮没有固定的链接,我的抓取工具可以跟随该链接,而下一页的URL与编号的按钮相同。这意味着,即使在请求了下一页网址后,末尾的数字也会发生变化,这使我无法提取下一页。我试图避免使用硒或飞溅,因为我试图仅通过Scrapy或Beautifull Soup获得结果。但是,我们将不胜感激。