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


Python HTMLParser.HTMLParseError方法代碼示例

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


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

示例1: feed

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def feed(self, markup):
        args, kwargs = self.parser_args
        parser = BeautifulSoupHTMLParser(*args, **kwargs)
        parser.soup = self.soup
        try:
            parser.feed(markup)
        except HTMLParseError, e:
            warnings.warn(RuntimeWarning(
                "Python's built-in HTMLParser cannot parse the given document. This is not a bug in Beautiful Soup. The best solution is to install an external parser (lxml or html5lib), and use Beautiful Soup with that parser. See http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser for help."))
            raise e

# Patch 3.2 versions of HTMLParser earlier than 3.2.3 to use some
# 3.2.3 code. This ensures they don't treat markup like <p></p> as a
# string.
#
# XXX This code can be removed once most Python 3 users are on 3.2.3. 
開發者ID:evait-security,項目名稱:weeman,代碼行數:18,代碼來源:_htmlparser.py

示例2: parse_declaration

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def parse_declaration(self, i):
        """Treat a bogus SGML declaration as raw data. Treat a CDATA
        declaration as a CData object."""
        j = None
        if self.rawdata[i:i+9] == '<![CDATA[':
             k = self.rawdata.find(']]>', i)
             if k == -1:
                 k = len(self.rawdata)
             data = self.rawdata[i+9:k]
             j = k+3
             self._toStringSubclass(data, CData)
        else:
            try:
                j = HTMLParser.parse_declaration(self, i)
            except HTMLParseError:
                toHandle = self.rawdata[i:]
                self.handle_data(toHandle)
                j = i + len(toHandle)
        return j 
開發者ID:pythonanywhere,項目名稱:dirigible-spreadsheet,代碼行數:21,代碼來源:BeautifulSoup.py

示例3: http_response

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def http_response(self, request, response):
        if not hasattr(response, "seek"):
            response = response_seek_wrapper(response)
        http_message = response.info()
        url = response.geturl()
        ct_hdrs = http_message.getheaders("content-type")
        if is_html(ct_hdrs, url, self._allow_xhtml):
            try:
                try:
                    html_headers = parse_head(response,
                                              self.head_parser_class())
                finally:
                    response.seek(0)
            except (HTMLParser.HTMLParseError,
                    sgmllib.SGMLParseError):
                pass
            else:
                for hdr, val in html_headers:
                    # add a header
                    http_message.dict[hdr.lower()] = val
                    text = hdr + ": " + val
                    for line in text.split("\n"):
                        http_message.headers.append(line + "\n")
        return response 
開發者ID:rajeshmajumdar,項目名稱:BruteXSS,代碼行數:26,代碼來源:_http.py

示例4: feed

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def feed(self, markup):
        args, kwargs = self.parser_args
        parser = BeautifulSoupHTMLParser(*args, **kwargs)
        parser.soup = self.soup
        try:
            parser.feed(markup)
        except HTMLParseError, e:
            warnings.warn(RuntimeWarning(
                "Python's built-in HTMLParser cannot parse the given document. This is not a bug in Beautiful Soup. The best solution is to install an external parser (lxml or html5lib), and use Beautiful Soup with that parser. See http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser for help."))
            raise e 
開發者ID:MarcelloLins,項目名稱:ServerlessCrawler-VancouverRealState,代碼行數:12,代碼來源:_htmlparser.py

示例5: _parse_error

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def _parse_error(self, source):
        def parse(source=source):
            parser = HTMLParser.HTMLParser()
            parser.feed(source)
            parser.close()
        self.assertRaises(HTMLParser.HTMLParseError, parse) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_htmlparser.py

示例6: StripTags

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def StripTags(str):
  """Returns the string with HTML tags stripped.

  Args:
    str: An html string.

  Returns:
    The html string with all tags stripped. If there was a parse error, returns
    the text successfully parsed so far.
  """
  # Brute force approach to stripping as much HTML as possible. If there is a
  # parsing error, don't strip text before parse error position, and continue
  # trying from there.
  final_text = ''
  finished = False
  while not finished:
    try:
      strip = _HtmlStripper()
      strip.feed(str)
      strip.close()
      str = strip.get_output()
      final_text += str
      finished = True
    except HTMLParser.HTMLParseError, e:
      final_text += str[:e.offset]
      str = str[e.offset + 1:] 
開發者ID:google,項目名稱:closure-linter,代碼行數:28,代碼來源:htmlutil.py

示例7: feed

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def feed(self, data):
            try:
                HTMLParser.HTMLParser.feed(self, data)
            except HTMLParser.HTMLParseError, exc:
                raise ParseError(exc) 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:7,代碼來源:clientform.py

示例8: feed

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def feed(self, data):
        try:
            HTMLParser.HTMLParser.feed(self, data)
        except HTMLParser.HTMLParseError, exc:
            raise ParseError(exc) 
開發者ID:rajeshmajumdar,項目名稱:BruteXSS,代碼行數:7,代碼來源:_form.py

示例9: strip_tags

# 需要導入模塊: import HTMLParser [as 別名]
# 或者: from HTMLParser import HTMLParseError [as 別名]
def strip_tags(html):
    s = HTMLTagStripper()
    try:
        s.feed(html)
    except HTMLParseError:
        get_logger().error('error stripping tags', raw_html=html)
    return s.get_data()

# https://djangosnippets.org/snippets/19/ 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:11,代碼來源:html.py


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