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


Python robotparser.RobotFileParser方法代碼示例

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


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

示例1: testPasswordProtectedSite

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def testPasswordProtectedSite(self):
        test_support.requires('network')
        with test_support.transient_internet('mueblesmoraleda.com'):
            url = 'http://mueblesmoraleda.com'
            robots_url = url + "/robots.txt"
            # First check the URL is usable for our purposes, since the
            # test site is a bit flaky.
            try:
                urlopen(robots_url)
            except HTTPError as e:
                if e.code not in {401, 403}:
                    self.skipTest(
                        "%r should return a 401 or 403 HTTP error, not %r"
                        % (robots_url, e.code))
            else:
                self.skipTest(
                    "%r should return a 401 or 403 HTTP error, not succeed"
                    % (robots_url))
            parser = robotparser.RobotFileParser()
            parser.set_url(url)
            try:
                parser.read()
            except IOError:
                self.skipTest('%s is unavailable' % url)
            self.assertEqual(parser.can_fetch("*", robots_url), False) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:27,代碼來源:test_robotparser.py

示例2: setUp

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def setUp(self):
        lines = StringIO.StringIO(self.robots_txt).readlines()
        self.parser = robotparser.RobotFileParser()
        self.parser.parse(lines) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_robotparser.py

示例3: testPasswordProtectedSite

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def testPasswordProtectedSite(self):
        addr = self.server.server_address
        url = 'http://' + support.HOST + ':' + str(addr[1])
        robots_url = url + "/robots.txt"
        parser = robotparser.RobotFileParser()
        parser.set_url(url)
        parser.read()
        self.assertFalse(parser.can_fetch("*", robots_url)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_robotparser.py

示例4: setUpClass

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def setUpClass(cls):
        support.requires('network')
        with support.transient_internet(cls.base_url):
            cls.parser = robotparser.RobotFileParser(cls.robots_txt)
            cls.parser.read() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_robotparser.py

示例5: test_read_404

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def test_read_404(self):
        parser = robotparser.RobotFileParser(self.url('i-robot.txt'))
        parser.read()
        self.assertTrue(parser.allow_all)
        self.assertFalse(parser.disallow_all)
        self.assertEqual(parser.mtime(), 0) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_robotparser.py

示例6: RobotTest

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def RobotTest(index, robots_txt, good_urls, bad_urls,
              agent="test_robotparser"):

    lines = StringIO.StringIO(robots_txt).readlines()
    parser = robotparser.RobotFileParser()
    parser.parse(lines)
    for url in good_urls:
        tests.addTest(RobotTestCase(index, parser, url, 1, agent))
    for url in bad_urls:
        tests.addTest(RobotTestCase(index, parser, url, 0, agent))

# Examples from http://www.robotstxt.org/wc/norobots.html (fetched 2002)

# 1. 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:16,代碼來源:test_robotparser.py

示例7: testPythonOrg

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def testPythonOrg(self):
        test_support.requires('network')
        with test_support.transient_internet('www.python.org'):
            parser = robotparser.RobotFileParser(
                "http://www.python.org/robots.txt")
            parser.read()
            self.assertTrue(
                parser.can_fetch("*", "http://www.python.org/robots.txt")) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:10,代碼來源:test_robotparser.py

示例8: addrobot

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def addrobot(self, root):
        root = urlparse.urljoin(root, "/")
        if self.robots.has_key(root): return
        url = urlparse.urljoin(root, "/robots.txt")
        self.robots[root] = rp = robotparser.RobotFileParser()
        self.note(2, "Parsing %s", url)
        rp.debug = self.verbose > 3
        rp.set_url(url)
        try:
            rp.read()
        except (OSError, IOError), msg:
            self.note(1, "I/O error parsing %s: %s", url, msg) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:14,代碼來源:webchecker.py

示例9: testPythonOrg

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def testPythonOrg(self):
        test_support.requires('network')
        with test_support.transient_internet('www.python.org'):
            parser = robotparser.RobotFileParser(
                "https://www.python.org/robots.txt")
            parser.read()
            self.assertTrue(
                parser.can_fetch("*", "https://www.python.org/robots.txt")) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:10,代碼來源:test_robotparser.py

示例10: runTest

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def runTest(self):
        test_support.requires('network')
        # whole site is password-protected.
        url = 'http://mueblesmoraleda.com'
        parser = robotparser.RobotFileParser()
        parser.set_url(url)
        parser.read()
        self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:10,代碼來源:test_robotparser.py

示例11: __init__

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def __init__(self, url='', opener=None):
        robotparser.RobotFileParser.__init__(self, url)
        self._opener = opener
        self._timeout = _sockettimeout._GLOBAL_DEFAULT_TIMEOUT 
開發者ID:rajeshmajumdar,項目名稱:BruteXSS,代碼行數:6,代碼來源:_http.py

示例12: RobotTest

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def RobotTest(index, robots_txt, good_urls, bad_urls,
              agent="test_robotparser"):

    lines = StringIO(robots_txt).readlines()
    parser = robotparser.RobotFileParser()
    parser.parse(lines)
    for url in good_urls:
        tests.addTest(RobotTestCase(index, parser, url, 1, agent))
    for url in bad_urls:
        tests.addTest(RobotTestCase(index, parser, url, 0, agent))

# Examples from http://www.robotstxt.org/wc/norobots.html (fetched 2002)

# 1. 
開發者ID:Acmesec,項目名稱:CTFCrackTools-V2,代碼行數:16,代碼來源:test_robotparser.py

示例13: testPythonOrg

# 需要導入模塊: import robotparser [as 別名]
# 或者: from robotparser import RobotFileParser [as 別名]
def testPythonOrg(self):
        support.requires('network')
        with support.transient_internet('www.python.org'):
            parser = robotparser.RobotFileParser(
                "http://www.python.org/robots.txt")
            parser.read()
            self.assertTrue(
                parser.can_fetch("*", "http://www.python.org/robots.txt")) 
開發者ID:Acmesec,項目名稱:CTFCrackTools-V2,代碼行數:10,代碼來源:test_robotparser.py


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