Pythonである関数で取得した文字列を別の関数で解析したいのですがPythonの関数の関数での値渡しの方法がいまいちわかっていないのでご教授していただけると助かります。
環境
python3.5.2
Python
1import scrapy 2import re 3 4from myproject.items import SceduleItem 5 6class TestSpider(scrapy.Spider): 7 name = "test6" 8 allowed_domains = ["*******"] 9 start_urls = ( 10 '*********', 11 ) 12 13 def parse(self, response): 14 for get_box in response.xpath('//div[@class="**********"]'): 15 16 17 def parse_info(self, response,): 18 item = SceduleItem() 19 day = info.xpath('//h3/text()').extract_first().strip() 20 for hall_info in info.xpath('//ul/li/div[@class="************"]'): 21 shop = hall_info.xpath('//div[@class="********"]/div[@class="name"]/a/text()').extract_first().strip() 22 place = hall_info.xpath('//div[@class="********"]/div[@class="area"]/text()').extract_first() 23 cast = hall_info.xpath('//div[@class="********"]/div[@class="text"]/div[@class="syutsuen"]/text()').extract_first() 24 content = hall_info.xpath('//div[@class="********"]/div[@class="text"]/div[@class="bangumi"]/text()').extract_first() 25 item['day'] = day 26 item['place'] = place 27 item['shop'] = shop 28 item['content'] = cast + '' + content 29 yield item 30 31
上記のようなコードで、parse関数でHTML要素からboxを取得し、parse_info関数で、parseで取得したbox内のboxを解析したいのですが、関数同士の値渡しがいまいちよくわからなく、うまくいきません。
実現したいこと
parseで取得したboxを格納したget_boxをparse_infoに値が渡せればいいです。
やり方をおねがいします。
あなたの回答
tips
プレビュー