Я все еще новичок в этом, и мне интересно, есть ли более простой способ отделить текст.Прямо сейчас я работаю в Excel и имею несколько данных в одной ячейке.Разделять их не весело ? На самом деле мои данные, класс из трех полей (), выглядит следующим образом (у каждого A может быть многократное число B; у каждого B есть 7x C):
A, «B1, B2»,«C1, C2, C3,…, C14»
И я хотел бы заполнить / сохранить его так:
A, B1, C1
A, B1, C2
…
A, B1, C7
A, B2,…
Это мой код:
class Heroes1Item(scrapy.Item):
hero_name = scrapy.Field()
hero_builds = scrapy.Field()
hero_buildskills = scrapy.Field()
и
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
Спасибо за вашу помощь и любые идеи!