【发布时间】:2021-08-15 13:22:11
【问题描述】:
下面是我对scrapy spider的解析方法。我在 csv 中的预期输出是具有相应值的三列。尽管在终端输出中我得到了所有三列(即使它显示了 output.csv 中存储的 84 个项目,这是正确的)。但在实际输出文件中,我只有第一列“标题。帮助表示赞赏
编辑:在 JSON 中,所有数据都在那里
def parse(self, response):
for titl in response.xpath('//span[@class="jv-job-list-title"]/text()').extract():
title = titl.strip()
yield {"Title":title}
for dep in response.xpath('//span[@class="jv-job-list-title"]/text()').extract():
department = dep.strip()
yield{"Department":department}
for countr in response.xpath('//td[@class="jv-job-list-name"]/span[2]/text()').extract():
country = countr.strip()
yield{"Country":country}
scrapy crawl task -o output.csv
完整代码:
class TaskUs(scrapy.Spider):
name = 'task'
start_urls = ["https://jobs.jobvite.com/taskus-inc/search?c=Workforce%20Management&p=0"]
# def start_requests(self):
# for URL in self.start_urls:
# yield scrapy.Request(url=URL, meta={'proxy': 'http://103.241.227.108:6666'}, callback=self.parse)
def parse(self, response):
# for titl in response.xpath('//span[@class="jv-job-list-title"]/text()').extract():
# title = titl.strip()
# yield {"Title":title}
# for dep in response.xpath('//span[@class="jv-job-list-category"]/text()').extract():
# department = dep.strip()
# yield{"Department":department}
# for countr in response.xpath('//td[@class="jv-job-list-name"]/span[2]/text()').extract():
# country = countr.strip()
# yield{"Country":country}
ti = response.xpath('//span[@class="jv-job-list-title"]/text()').extract()
de = response.xpath('//span[@class="jv-job-list-category"]/text()').extract()
co = response.xpath('//td[@class="jv-job-list-name"]/span[2]/text()').extract()
yield{'titl':ti, 'Depa': de, "Cou": co}
【问题讨论】: