I´m still new to this and im wondering, if there is an easier way, to separate text. Right now i`m working in excel and have multiple Data in one Cell. Separating them is no fun Actually my data, a class of three fields(), looks like this (Each A can have mupltiple B; Each B has 7x C):
A, “B1,B2”, “C1,C2,C3,…, C14”
And I´d like to fill/save it like this:
A, B1, C1
A, B1, C2
…
A, B1, C7
A, B2, …
This is my code:
class Heroes1Item(scrapy.Item):
hero_name = scrapy.Field()
hero_builds = scrapy.Field()
hero_buildskills = scrapy.Field()
and
import scrapy
from heroes1.items import Heroes1Item
from scrapy import Request, Item, Field
class Heroes1JobSpider(scrapy.Spider):
name = 'heroes1_job'
allowed_domains = ['icy-veins.com']
start_urls = ['https://www.icy-veins.com/heroes/assassin-hero-guides']
def parse(self, response):
heroes_xpath = '//div[@class="nav_content_block_entry_heroes_hero"]/a/@href'
for link in response.xpath(heroes_xpath).extract():
yield Request(response.urljoin(link), self.parse_hero)
def parse_hero(self, response):
hero_names = response.xpath('//span[@class="page_breadcrumbs_item"]/text()').extract()
hero_buildss = response.xpath('//h3[@class="toc_no_parsing"]/text()').extract()
hero_buildskillss = response.xpath('//span[@class="heroes_build_talent_tier_visual"]').extract()
for item in zip(hero_names, hero_buildss, hero_buildskillss):
new_item = Heroes1Item()
new_item['hero_name'] = item[0]
#new_item['hero_builds'] = item[1] DATALOSS
#new_item['hero_buildskills'] = item[2] DATALOSS
new_item['hero_builds'] = response.xpath('//h3[@class="toc_no_parsing"]/text()').extract()
new_item['hero_buildskills'] = response.xpath('//span[@class="heroes_build_talent_tier_visual"]').extract()
yield new_item
Thanks for your help and any ideas!