【问题标题】:Scrapy how to extract the text of the field that you are not selecting onScrapy如何提取您未选择的字段的文本
【发布时间】:2019-02-18 22:57:21
【问题描述】:

我是 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 中获取文本?谢谢!

【问题讨论】:

    标签: python scrapy


    【解决方案1】:

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

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

    【讨论】:

    • 请注意,如果您真的不打算使用next_page_outer,可以将其简化为一个XPath:response.xpath('//link[@rel="next"]/@href').get()
    猜你喜欢
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 2014-04-21
    • 2021-10-08
    • 1970-01-01
    • 2018-09-30
    相关资源
    最近更新 更多