Issue
I have this element in the html document
<div class="main-l">
<i class="icon icon-small icon-pin"></i> 65203 Wiesbaden</div>
trying to get the lement with .css('.main-l::text').get()
give me only the partial text: '\r\n '
. This is the text before the i
element.
How to get the full text or the text after the i
element?
Solution
To get full text, you have to call .getall()
method
response.css('.main-l::text').getall()
Proved by scrapy shell
In [1]: from scrapy.selector import Selector
In [2]: %paste
html='''
<div class="main-l">
<i class="icon icon-small icon-pin"></i> 65203 Wiesbaden</div>
'''
## -- End pasted text --
In [3]: response = Selector(text=html)
In [4]:
...: ' '.join(response.css('.main-l::text').getall()).strip()
Out[4]: '65203 Wiesbaden'
Answered By - F.Hoque
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.