scrapy: convert html string to HtmlResponse object

前端 未结 2 1862
时光取名叫无心
时光取名叫无心 2021-01-31 18:04

I have a raw html string that I want to convert to scrapy HTML response object so that I can use the selectors css and xpath, similar to scrapy\'s

2条回答
  •  旧时难觅i
    2021-01-31 18:51

    alecxe's answer is right, but this is the correct way to instantiate a Selector from text in scrapy:

    >>> from scrapy.selector import Selector
    >>> body = 'good'
    >>> Selector(text=body).xpath('//span/text()').get()
    
    'good'
    

提交回复
热议问题