コード例 #1
0
ファイル: scraper.py プロジェクト: einaru/takeaway-menues
    def _processSubmenu(self, soup):
        """Scrape a Bryggen Asian Cooking submenu.

        Each submenu is inside a table:

            <table>
                <tr>
                    <td>Menu item name<br/>possible description</td>
                    <td>Menu item price</td>
                    <td>IGNORE</td>
                </tr>
                ...
            </table>

        :param soup: the `BeautifulSoup` object holding submenu data.
        :type soup: `BeautifulSoup`
        :rtype: list of `MenuItem`
        """
        items = []
        for row in soup.findAll('tr'):
            td = row.findAll('td', limit=2)
            info = td[0].contents
            name = info[0]
            if len(info) > 1:
                desc = info[2].encode('utf-8').strip('\n')
            else:
                desc = u''
            price = util.formatPrice(td[1].contents[0])

            items.append(MenuItem(name, desc, price))

        return items
コード例 #2
0
ファイル: scraper.py プロジェクト: einaru/takeaway-menues
    def _processSubmenu(self, soup):
        """Scrapes a Kyoto submenu.

        Html structure for takeout (sub)menu::

            <table class="menytabell">
              <tbody>
                <tr>
                  <td class="menyinfo">Item info</td>
                  <td class="menypris">Item price</td>
                </tr>
                ...
              </tbody>
            </table>

        :param soup: the BeautifulSoup object holding a Kyoto submenu
         page.
        :type soup: `BeautifulSoup`
        """
        items = []
        table = soup.find('table', 'menytabell')
        for row in table.findAll('tr'):
            info = row.find('td', 'menyinfo')
            name, desc = self._processMenuinfo(info)
            price = row.find('td', 'menypris').contents[0]
            price = util.formatPrice(price)

            items.append(MenuItem(name, desc, price))

        return items