我从Indeed下载了一个页面的源代码,并试图从中获取所有的职位,为此,我使用以下xpath:
response.xpath('//*[@class=" row result"]//*[@class="jobtitle"]//text()').extract()
问题是结果不在一行,因此得到的结果是:
^{pr2}$第一个要提取的数据有问题吗
response.xpath('//*[@class=" row result"]').extract_first()
但是对于任何给定的索引,并且可以选择继续处理数据。 我试过了:
current_job = response.xpath('//*[@class=" row result"]').extract_first()
current_job = TextResponse(url='',body=current_job,encoding='utf-8')
但它只适用于第一个结果,对我来说这不像一个Python式的方法。在
试试看。你需要稍微修改一下我的脚本以适合你的项目。你可以解决上面提到的问题。在
输出:
^{pr2}$首先,我只得到}与every
a
(没有text()
和extract()
),然后我将使用for
将text()
和{a
分开使用,而join()
将元素连接到带标题的字符串中。在结果:
^{pr2}$相关问题 更多 >
编程相关推荐