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


Python urllib.html方法代碼示例

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


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

示例1: test_short_content_raises_ContentTooShortError

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import html [as 別名]
def test_short_content_raises_ContentTooShortError(self):
        self.fakehttp('''HTTP/1.1 200 OK
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Length: 100
Content-Type: text/html; charset=iso-8859-1

FF
''')

        def _reporthook(par1, par2, par3):
            pass

        try:
            self.assertRaises(urllib.ContentTooShortError, urllib.urlretrieve,
                    'http://example.com', reporthook=_reporthook)
        finally:
            self.unfakehttp() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_urllib.py

示例2: test_url_fragment

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import html [as 別名]
def test_url_fragment(self):
        # Issue #11703: geturl() omits fragments in the original URL.
        url = 'http://docs.python.org/library/urllib.html#OK'
        self.fakehttp('Hello!')
        try:
            fp = urllib.urlopen(url)
            self.assertEqual(fp.geturl(), url)
        finally:
            self.unfakehttp() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_urllib.py

示例3: test_read_bogus

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import html [as 別名]
def test_read_bogus(self):
        # urlopen() should raise IOError for many error codes.
        self.fakehttp('''HTTP/1.1 401 Authentication Required
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Type: text/html; charset=iso-8859-1
''')
        try:
            self.assertRaises(IOError, urllib.urlopen, "http://python.org/")
        finally:
            self.unfakehttp() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_urllib.py

示例4: test_invalid_redirect

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import html [as 別名]
def test_invalid_redirect(self):
        # urlopen() should raise IOError for many error codes.
        self.fakehttp("""HTTP/1.1 302 Found
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Location: file:README
Connection: close
Content-Type: text/html; charset=iso-8859-1
""")
        try:
            msg = "Redirection to url 'file:"
            with self.assertRaisesRegexp(IOError, msg):
                urllib.urlopen("http://python.org/")
        finally:
            self.unfakehttp() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:test_urllib.py

示例5: test_short_content_raises_ContentTooShortError_without_reporthook

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import html [as 別名]
def test_short_content_raises_ContentTooShortError_without_reporthook(self):
        self.fakehttp('''HTTP/1.1 200 OK
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Length: 100
Content-Type: text/html; charset=iso-8859-1

FF
''')
        try:
            self.assertRaises(urllib.ContentTooShortError, urllib.urlretrieve, 'http://example.com/')
        finally:
            self.unfakehttp() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_urllib.py

示例6: test_invalid_redirect

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import html [as 別名]
def test_invalid_redirect(self):
        # urlopen() should raise IOError for many error codes.
        self.fakehttp("""HTTP/1.1 302 Found
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Location: file:README
Connection: close
Content-Type: text/html; charset=iso-8859-1
""")
        try:
            self.assertRaises(IOError, urllib.urlopen, "http://python.org/")
        finally:
            self.unfakehttp() 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:15,代碼來源:test_urllib.py


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