Scrapy如何提取未选择的字段的文本

时间:2019-02-18 22:57:21

标签: python scrapy

我是python / scrapy的新手。我的问题与此问题相似,但我无法完全制定出有效的答案:

How Scrapy extract text inside class that inside attribute?

这是我的代码:

import scrapy

class IndeedSpider(scrapy.Spider):
    name='indeed_jobs'
    start_urls = ['https://www.indeed.com/q-Software-Engineer-l-Portland,-OR-jobs.html']

    def parse(self, response):
        next_page_outer = './/link[@rel="next"]'
        next_page_url_outer = response.xpath(next_page_outer).get()
        print(next_page_url_outer)  

该代码产生:

<link rel="next" href="/jobs?q=Software+Engineer&amp;l=Portland%2C+OR&amp;start=10">

如何从此响应中包含的href中获取文本?谢谢!

1 个答案:

答案 0 :(得分:0)

我可以回答我自己的问题。答案是:

next_page_url_href = response.xpath(next_page_outer).xpath("@href").extract()