예제 #1
0
    def ingredients(self):
        ingdivs = self.hxs.select('//table[@width="333"]/tr')
        ingredients = []
        principal_section = dict(section_name='principal', ings=[])
        sauce_section = dict(section_name='sauce', ings=[])
        for idiv in ingdivs:
            ele = idiv.root
            ### ingredients
            ing = ele.find('.//td[@width="306"]')
            ing_name = get_text_or_none(ing)
            amount = ele.find('.//td[@width="105"]')
            ing_amount = get_text_or_none(amount)
            if ing_name:
                principal_section['ings'].append(
                    dict(name=ing_name, amount=ing_amount))

            ### sauce
            ing = ele.find('.//td[@width="231"]')
            ing_name = get_text_or_none(ing)
            amount = ele.find('.//td[@width="102"]')
            ing_amount = get_text_or_none(amount)
            if ing_name:
                sauce_section['ings'].append(
                    dict(name=ing_name, amount=ing_amount))

        ingredients = [principal_section, sauce_section]
        return ingredients
예제 #2
0
파일: cookshow.py 프로젝트: yytsui/cheese
    def ingredients(self):
        ingdivs = self.hxs.select('//table[@width="333"]/tr')
        ingredients = []
        principal_section = dict(section_name='principal', ings=[])
        sauce_section = dict(section_name='sauce', ings=[])
        for idiv in ingdivs:
            ele = idiv.root
            ### ingredients
            ing = ele.find('.//td[@width="306"]')
            ing_name = get_text_or_none(ing)
            amount = ele.find('.//td[@width="105"]')
            ing_amount = get_text_or_none(amount)
            if ing_name:
                principal_section['ings'].append(dict(name=ing_name, amount=ing_amount))

            ### sauce
            ing = ele.find('.//td[@width="231"]')
            ing_name = get_text_or_none(ing)
            amount = ele.find('.//td[@width="102"]')
            ing_amount = get_text_or_none(amount)
            if ing_name:
                sauce_section['ings'].append(dict(name=ing_name, amount=ing_amount))

        ingredients = [principal_section, sauce_section]
        return ingredients
예제 #3
0
    def ingredients(self):
        ingdivs = self.hxs.select('//ul[@itemprop="ingredient"]/li/div')
        ingredients = []
        ings_1 = []
        for idiv in ingdivs:
            ele = idiv.root
            ing = ele.find('.//span[@itemprop="name"]')
            ing_name = get_text_or_none(ing)
            amount = ele.find('.//span[@itemprop="amount"]')
            ing_amout = get_text_or_none(amount)
            ings_1.append(dict(name=ing_name, amount=ing_amout))
        ingredients.append(dict(section_name='principal', ings=ings_1))

        ululs = self.hxs.select('//ul[@itemprop="ingredient"]/ul')
        if ululs is not None:
            for ul in ululs:
                _ul = ul.root
                section_name = _ul.find('.//li[@class="group-name"]').text
                ings = []
                for ele in _ul.findall('.//li/div'):
                    ing = ele.find('.//span[@itemprop="name"]')
                    ing_name = get_text_or_none(ing)
                    amount = ele.find('.//span[@itemprop="amount"]')
                    ing_amout = get_text_or_none(ing)
                    ings.append(dict(name=ing_name, amount=ing_amout))
                ingredients.append(dict(section_name=section_name, ings=ings))

        return ingredients
예제 #4
0
파일: icooktw.py 프로젝트: yytsui/cheese
    def ingredients(self):
        ingdivs = self.hxs.select('//ul[@itemprop="ingredient"]/li/div')
        ingredients = []
        ings_1 = []
        for idiv in ingdivs:
            ele = idiv.root
            ing = ele.find('.//span[@itemprop="name"]')
            ing_name = get_text_or_none(ing)
            amount = ele.find('.//span[@itemprop="amount"]')
            ing_amout = get_text_or_none(amount)
            ings_1.append(dict(name=ing_name, amount=ing_amout))
        ingredients.append(dict(section_name='principal', ings=ings_1))

        ululs = self.hxs.select('//ul[@itemprop="ingredient"]/ul')
        if ululs is not None:
            for ul in ululs:
                _ul = ul.root
                section_name = _ul.find('.//li[@class="group-name"]').text
                ings = []
                for ele in _ul.findall('.//li/div'):
                    ing = ele.find('.//span[@itemprop="name"]')
                    ing_name = get_text_or_none(ing)
                    amount = ele.find('.//span[@itemprop="amount"]')
                    ing_amout = get_text_or_none(ing)
                    ings.append(dict(name=ing_name, amount=ing_amout))
                ingredients.append(dict(section_name=section_name, ings=ings))

        return ingredients
예제 #5
0
    def ingredients(self):
        ingdivs = self.hxs.select('//div[@class="Material"]')
        ingredients = []
        for idiv in ingdivs:
            ele = idiv.root
            ings = []
            section_name = ele.find('.//div[@class="Title"]').text
            itemeles = ele.findall('.//div[@class="Item"]')
            for iele in itemeles:
                ing = iele.find('.//span[@class="Name"]')
                ing_name = get_text_or_none(ing)
                amount = iele.find('.//span[@class="Quantity"]')
                ing_amout = get_text_or_none(amount)
                ings.append(dict(name=ing_name, amount=ing_amout))
            ingredients.append(dict(section_name=section_name, ings=ings))

        return ingredients
예제 #6
0
파일: ytower.py 프로젝트: yytsui/cheese
 def ingredients(self):
     trs = self.hxs.select('//td[@width="200"]/table/tr')
     ingredients = []
     for tr in trs:
         ele = tr.root # lxml element
         section =  ele.find('.//td[@colspan="2"]/font')
         section_name = get_text_or_none(section)
         if section_name:
             section_dict = dict(section=section_name,ings=[])
             ingredients.append(section_dict)
         ing = ele.find('.//td[@width="68%"]/a[@class="sh13pt_link"]')
         ing_name = get_text_or_none(ing)
         amount = ele.find('.//td[@width="32%"]')
         ing_amount = get_text_or_none(amount)
         if ing_name:
             section_dict['ings'].append(dict(name=ing_name, amount=ing_amount))
     return ingredients
예제 #7
0
 def ingredients(self):
     trs = self.hxs.select('//td[@width="200"]/table/tr')
     ingredients = []
     for tr in trs:
         ele = tr.root  # lxml element
         section = ele.find('.//td[@colspan="2"]/font')
         section_name = get_text_or_none(section)
         if section_name:
             section_dict = dict(section=section_name, ings=[])
             ingredients.append(section_dict)
         ing = ele.find('.//td[@width="68%"]/a[@class="sh13pt_link"]')
         ing_name = get_text_or_none(ing)
         amount = ele.find('.//td[@width="32%"]')
         ing_amount = get_text_or_none(amount)
         if ing_name:
             section_dict['ings'].append(
                 dict(name=ing_name, amount=ing_amount))
     return ingredients
예제 #8
0
    def steps(self):
        ps = self.hxs.select('//div[@class="ProcedureBox2"]') or\
                self.hxs.select('//span[@class="Process"]')

        steps = []
        for i, p in enumerate(ps):
            lele = p.root
            order = i + 1
            image = lele.find('.//img')
            if image is not None:
                picture = image.attrib['src']
            else:
                picture = None
            instruction_ele = lele.find('.//pre')
            instruction = get_text_or_none(instruction_ele)
            steps.append(dict(order=order, instruction=instruction, picture=picture))
        return steps