Reputation: 1067
I do this:
xmlstr="<root><first>info</first></root>"
res = Selector(text=xmlstr).xpath('.').getall()
print(res)
The output is:
['<html><body><root><first>info</first></root></body></html>']
How can I stop Selector wrapping the xml with html and body? Thanks
Upvotes: 1
Views: 45
Reputation: 28236
scrapy.Selector assumes html, but takes a type
argument to change that.
type
defines the selector type, it can be"html"
,"xml"
orNone
(default).If
type
isNone
, the selector automatically chooses the best type based onresponse
type (see below), or defaults to"html"
in case it is used together with text.
So, to make an xml selector, simply use Selector(text=xmlstr, type='xml')
Upvotes: 3