當前位置: 首頁>>代碼示例>>Python>>正文


Python bs4.FeatureNotFound方法代碼示例

本文整理匯總了Python中bs4.FeatureNotFound方法的典型用法代碼示例。如果您正苦於以下問題:Python bs4.FeatureNotFound方法的具體用法?Python bs4.FeatureNotFound怎麽用?Python bs4.FeatureNotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bs4的用法示例。


在下文中一共展示了bs4.FeatureNotFound方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import bs4 [as 別名]
# 或者: from bs4 import FeatureNotFound [as 別名]
def __init__(self, source_data, logger=None):
        super().__init__(source_data)

        if logger:
            self.__logger = logger
        else:
            self.__logger = NullSourceLogger(None)

        self.__table_id = None

        if typepy.is_null_string(source_data):
            raise DataError

        try:
            self.__soup = bs4.BeautifulSoup(self._source_data, "lxml")
        except bs4.FeatureNotFound:
            self.__soup = bs4.BeautifulSoup(self._source_data, "html.parser") 
開發者ID:thombashi,項目名稱:pytablereader,代碼行數:19,代碼來源:formatter.py

示例2: __init__

# 需要導入模塊: import bs4 [as 別名]
# 或者: from bs4 import FeatureNotFound [as 別名]
def __init__(self, markup, parsers, **kwargs):
        # reject features
        if set(parsers).intersection({'fast', 'permissive', 'strict', 'xml', 'html', 'html5'}):
            raise ValueError('Features not allowed, only parser names')

        # reject some kwargs
        if 'features' in kwargs:
            raise ValueError('Cannot use features kwarg')
        if 'builder' in kwargs:
            raise ValueError('Cannot use builder kwarg')

        # pick the first parser available
        for parser in parsers:
            try:
                super(ParserBeautifulSoup, self).__init__(markup, parser, **kwargs)
                return
            except FeatureNotFound:
                pass

        raise FeatureNotFound 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:22,代碼來源:__init__.py

示例3: test_backend_parsers

# 需要導入模塊: import bs4 [as 別名]
# 或者: from bs4 import FeatureNotFound [as 別名]
def test_backend_parsers():
    """
    Make sure the user can specify which back-end parser to use
    and that an error is raised if the parser is invalid.
    """
    for parser in ('lxml', 'xml', 'html.parser', 'html5lib'):
        try:
            table = Table.read('data/html2.html', format='ascii.html',
                               htmldict={'parser': parser}, guess=False)
        except FeatureNotFound:
            if parser == 'html.parser':
                raise
            # otherwise ignore if the dependency isn't present

    # reading should fail if the parser is invalid
    with pytest.raises(FeatureNotFound):
        Table.read('data/html2.html', format='ascii.html',
                   htmldict={'parser': 'foo'}, guess=False) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:20,代碼來源:test_html.py

示例4: get_available_parsers

# 需要導入模塊: import bs4 [as 別名]
# 或者: from bs4 import FeatureNotFound [as 別名]
def get_available_parsers():
    """Return a list of parsers that can be used."""
    available = []
    for p in PARSERS:
        try:
            bs4.BeautifulSoup("", p)
        except bs4.FeatureNotFound:
            # Try the next parser
            continue
        else:
            available.append(p)
    return available 
開發者ID:BitLooter,項目名稱:htmlark,代碼行數:14,代碼來源:htmlark.py

示例5: create_node

# 需要導入模塊: import bs4 [as 別名]
# 或者: from bs4 import FeatureNotFound [as 別名]
def create_node(self, html, loc, meta={}):
        try:
            soup = BeautifulSoup(html,'lxml', parse_only=self.only_text)
            soup_title = BeautifulSoup(html,'lxml', parse_only=self.only_title)
        except FeatureNotFound:
            soup = BeautifulSoup(html,'html.parser', parse_only=self.only_text)
            soup_title = BeautifulSoup(html,'html.parser', parse_only=self.only_title)

        page_text = soup.find("div", {"id": "text"}).get_text(' ', strip=True).replace('\\(','').replace('\\)','').replace('\\[','').replace('\\]','').replace('$$','').replace('^','^')

        # What happens if there is not a title.
        if soup_title.title is not None:
            page_title = '{0}'.format(soup_title.title.string)
        else:
            page_title = ''

        # Should set default category?
        if 'category' in meta:
            page_category = meta['category']
        else:
            page_category = ''

        if self.siteurl != '':
            page_url = urljoin(self.siteurl, loc)
        else:
            page_url = loc

        node = {'title': page_title,
                'text': page_text,
                'tags': page_category,
                'loc': page_url}
        
        self.json_nodes.append(node) 
開發者ID:Fortran-FOSS-Programmers,項目名稱:ford,代碼行數:35,代碼來源:tipue_search.py


注:本文中的bs4.FeatureNotFound方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。