i am extracting data using scrapy and python.
the data sometimes include spaces. i was using normalize-space
with xpath to remove those spaces like this:
xpath('normalize-space(.//li[2]/strong/text())').extract()
It words very good. However, now i want to use normalize-space
with css selector.
I tried this:
car['Location'] = site.css('normalize-space(div[class=location]::text)').extract()
I got empty result though i get correct result if i removed the normalize-space..
please how to use it with css selector?
i tried
def normalize_whitespace(str):
import re
str = str.strip()
str = re.sub(r's+', ' ', str)
return str
and i called this fucntion like this:
car['Location'] = normalize_whitespace(site.css('div[class=location]::text').extract())
but i got empty result. why please?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…