python - scrapy: convert html string to HtmlResponse object -


i have raw html string want convert scrapy html response object can use selectors css , xpath, similar scrapy's response. how can it?

first of all, if debugging or testing purposes, can use scrapy shell:

$ cat index.html <div id="test">     test text </div>  $ scrapy shell index.html >>> response.xpath('//div[@id="test"]/text()').extract()[0].strip() u'test text' 

there different objects available in shell during session, response , request.


or, can instantiate htmlresponse class , provide html string in body:

>>> scrapy.http import htmlresponse >>> response = htmlresponse(url="my html string", body='<div id="test">test text</div>') >>> response.xpath('//div[@id="test"]/text()').extract()[0].strip() u'test text' 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -