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


Python element.Comment方法代碼示例

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


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

示例1: text_only

# 需要導入模塊: from bs4 import element [as 別名]
# 或者: from bs4.element import Comment [as 別名]
def text_only(self):
        """Returns the displayed text of a webpage (without HTML tags)"""
        if "text" in self.type and self.size:
            texts = self.soup.findAll(text=True)

            def is_visible(element):
                if len(element.strip()) == 0:
                    return False
                elif isinstance(element, Comment):
                    return False
                elif element.parent.name in ["style", "script", "[document]", "head", "title"]:
                    return False
                return True

            text = " ".join(filter(is_visible, texts)).replace("\r\n", " ").replace("\n", " ")
            return text
        return "" 
開發者ID:penetrate2hack,項目名稱:ITWSV,代碼行數:19,代碼來源:crawler.py

示例2: comment

# 需要導入模塊: from bs4 import element [as 別名]
# 或者: from bs4.element import Comment [as 別名]
def comment(self, content):
        "Handle comments as Comment objects."
        self.soup.endData()
        self.soup.handle_data(content)
        self.soup.endData(Comment) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:7,代碼來源:_lxml.py

示例3: tag_visible

# 需要導入模塊: from bs4 import element [as 別名]
# 或者: from bs4.element import Comment [as 別名]
def tag_visible(element):
    if element.parent.name in ['style', 'script', 'head', 'title', 'meta', '[document]']:
        return False
    if isinstance(element, Comment):
        return False
    return True 
開發者ID:C0D3D3V,項目名稱:Moodle-Downloader,代碼行數:8,代碼來源:moodleCrawler.py

示例4: study

# 需要導入模塊: from bs4 import element [as 別名]
# 或者: from bs4.element import Comment [as 別名]
def study(bs_node, parent=None, keyword=""):
    entries = []

    # if parent is None:
    #  print("Keyword is: {0}".format(keyword))
    if keyword in str(bs_node).lower():
        if isinstance(bs_node, element.Tag):
            if keyword in str(bs_node.attrs):

                for k, v in bs_node.attrs.items():
                    if keyword in v:
                        # print("Found in attribute value {0} of tag {1}".format(k, bs_node.name))
                        noscript = close_noscript(bs_node)
                        d = {"type": "attrval", "name": k, "tag": bs_node.name, "noscript": noscript}
                        if d not in entries:
                            entries.append(d)

                    if keyword in k:
                        # print("Found in attribute name {0} of tag {1}".format(k, bs_node.name))
                        noscript = close_noscript(bs_node)
                        d = {"type": "attrname", "name": k, "tag": bs_node.name, "noscript": noscript}
                        if d not in entries:
                            entries.append(d)

            elif keyword in bs_node.name:
                # print("Found in tag name")
                noscript = close_noscript(bs_node)
                d = {"type": "tag", "value": bs_node.name, "noscript": noscript}
                if d not in entries:
                    entries.append(d)

            # recursively search injection points for the same variable
            for x in bs_node.contents:
                for entry in study(x, parent=bs_node, keyword=keyword):
                    if entry not in entries:
                        entries.append(entry)

        elif isinstance(bs_node, element.Comment):
            # print("Found in comment, tag {0}".format(parent.name))
            noscript = close_noscript(bs_node)
            d = {"type": "comment", "parent": parent.name, "noscript": noscript}
            if d not in entries:
                entries.append(d)

        elif isinstance(bs_node, element.NavigableString):
            # print("Found in text, tag {0}".format(parent.name))
            noscript = close_noscript(bs_node)
            d = {"type": "text", "parent": parent.name, "noscript": noscript}
            if d not in entries:
                entries.append(d)

    return entries


# generate a list of payloads based on where in the webpage the js-code will be injected 
開發者ID:penetrate2hack,項目名稱:ITWSV,代碼行數:57,代碼來源:xss_utils.py


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