Issue
How to split a text value on comma, to get two datapoints from it?
My code:
details = response.xpath('//div[@class="article-info"]')
for detail in details:
body = detail.xpath('.//ul/li[1]/span[2]/span/text()').get()
item['body'] = released
yield item
My output:
293g (Wi-Fi) / 297g (Wi-Fi + Cellular), 6.3mm thickness
Desired output (Column A) | Weight
293g (Wi-Fi) / 297g (Wi-Fi + Cellular)
Desired output (Column B) | Dimensions
6.3mm
Solution
.split()
takes an argument, so you can do this .split(", ")
and unpack to weight
and thickness
.
Try this:
details = response.xpath('//div[@class="article-info"]')
for detail in details:
weight, thickness = detail.xpath('.//ul/li[1]/span[2]/span/text()').get().split(", ")
item['weight'] = weight
item['thickness'] = thickness.split()[0] # gets you 6.3mm only
yield item
Answered By - baduker
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.