当前位置: 首页>>代码示例>>Python>>正文


Python HTTP.get方法代码示例

本文整理汇总了Python中http.HTTP.get方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.get方法的具体用法?Python HTTP.get怎么用?Python HTTP.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.HTTP的用法示例。


在下文中一共展示了HTTP.get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Scanner

# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import get [as 别名]
class Scanner(object):

    FINGERPRINTS = [
        {
            "type": "git",
            "base": ".git",
            "files": ["index"]
        },
        {
            "type": "svn",
            "base": ".svn",
            "files": ["wc.db"]
        },
        {
            "type": "svn_old",
            "base": ".svn",
            "files": ["entries"]
        },
        #{
        #    "type": "hg",
        #    "base": ".hg",
        #    "files": ["store/00manifest.i"]
        #}
    ]

    SCHEMES = ["HTTP", "HTTPS"]

    def __init__(self, host):
        self.host = URL(host).replace(path = "", query = "", fragment = "")
        self.session = HTTP()
        self.session.headers['User-Agent'] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"

    def scan_host(self):
        for scheme in self.SCHEMES:
            for fingerprint in self.FINGERPRINTS:
                for file in fingerprint['files']:
                    url = self.host.replace(path = fingerprint['base'] + "/" + file, scheme = scheme)
                    url = str(url)

                    response = self.session.get(url, verify=False)

                    if response.status_code == 200 and self._filter_false_positive(response.content, fingerprint['type']):
                        return {
                                "file": file,
                                "type": fingerprint['type'],
                                "scheme": scheme,
                                "data": response.content,
                                "host": self.host.replace(scheme = scheme)
                        }
                    else:
                        pass
                        if(response.status_code == 200):
                            pass
                            #print "Failed: File exists, but failed verification."
                        else:
                            pass
                            #print "Failed: HTTP " + str(response.status_code)

        return False

    def _filter_false_positive(self, data, type):
        if "<html" in data and "</html>" in data:
            return False

        if type == "git":
            if data[0:4] != "DIRC":
                return False

        if type == "svn_old":
            if "dir" not in data or "file" not in data:
                return False

        if type == "svn":
            if data[0:13] != "SQLite format":
                return False

        if type == "hg":
            if not data.statswith(".hgtag"):
                return False

        return True
开发者ID:simontoft,项目名称:VCSRip,代码行数:83,代码来源:scanner.py


注:本文中的http.HTTP.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。