python - With scrapy, how can get part of xpath parsed result? -
here part of spider:
def parse(self, response): titles = htmlxpathselector(response).select('//li') title in titles: item = eksidefeitem() item['favori'] = title.select("//*[@id='entry-list']/li/@data-favorite-count").extract() item['entry'] = ['<a href=https://eksisozluk.com%s'%a in title.select("//*[@class='entry-date permalink']/@href").extract()] item['yazari'] = title.select("//*[@id='entry-list']/li/@data-author").extract() item['basligi'] = title.select("//*[@id='topic']/h1/@data-title").extract() item['tarih'] = title.select("//*[@id='entry-list']/li/footer/div[2]/a[1]/text()").extract() return item
i getting date , time item['tarih']
not exact date , time has values inside it. here example of parsed data it:
26.01.2017 20:04 ~ 20:07
i want use date part (10 characters left)
26.01.2017
how can that?
thanks
you use string slicing date:
item['tarih'] = title.select("//*[@id='entry-list']/li/footer/div[2]/a[1]/text()").extract() item['tarih'][0] = item['tarih'][0][:10]
but add validation (take @ datetime.datetime.strptime()
) make sure got valid date.
Comments
Post a Comment