【发布时间】:2020-08-18 14:48:21
【问题描述】:
我在抓取此网站搜索时遇到了一些问题:
我正在尝试从 de SimplyHired 的美国数据工程师搜索职位中提取这些元素:
但是当我尝试使用选择器模块对其中任何一个使用 xpath 定位器时,我会得到不同的结果和不同的顺序。
它们的输出也不匹配(例如,与 xpath 作业名称对应的索引与 xpath 位置中的位置的索引不同)。
这是我的代码:
from scrapy import Selector
import requests
response = requests.get('https://www.simplyhired.com/search?q=data+engineer&l=united+states&mi=exact&sb=dd&pn=1&job=X1yGOt2Y8QTJm0tYqyptbgV9Pu19ge0GkVZK7Im5WbXm-zUr-QMM-A').content
sel=Selector(text=response)
#job name
sel.xpath('//main[@id="job-list"]/div/article[contains(@class,"SerpJob")]/div/div[@class="jobposting-title-container"]/h2/a/text()').extract()
#company
sel.xpath('//main[@id="job-list"]/div/article/div/h3[@class="jobposting-subtitle"]/span[@class="JobPosting-labelWithIcon jobposting-company"]/text()').extract()
#location
sel.xpath('//main[@id="job-list"]//div/article/div/h3[@class="jobposting-subtitle"]/span[@class="JobPosting-labelWithIcon jobposting-location"]/span/span/text()').extract()
#salary estimates
sel.xpath('//main[@id="job-list"]//div/article/div/div[@class="SerpJob-metaInfo"]//div[@class="SerpJob-metaInfoLeft"]/span/text()[2]').extract()
【问题讨论】:
标签: python web-scraping scrapy