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


Python urllib.FancyURLopener方法代码示例

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


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

示例1: proxyvalidator

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def proxyvalidator(proxylist):
        finalcount = 0
	for proxy in proxylist:
		proxy.replace('\n', '')
		try:
			proxies = {'http': "http://"+proxy[:-1]}
			opener = urllib.FancyURLopener(proxies)
			try:
				loopchk = opener.open("http://www.google.com").read()
			except:
				pass
		except(IOError,socket.timeout), detail: 
			pass
		ipcheck(proxy)		
		alivelist.append(proxy)
		finalcount += 1 
开发者ID:knightmare2600,项目名称:d4rkc0de,代码行数:18,代码来源:ProxyHarvest.py

示例2: __init__

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)
        self.errcode = 200 
开发者ID:glmcdona,项目名称:meddle,代码行数:5,代码来源:robotparser.py

示例3: http_error_default

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def http_error_default(self, url, fp, errcode, errmsg, headers):
        self.errcode = errcode
        return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
                                                        errmsg, headers) 
开发者ID:glmcdona,项目名称:meddle,代码行数:6,代码来源:robotparser.py

示例4: test_getcode

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def test_getcode(self):
        # test getcode() with the fancy opener to get 404 error codes
        URL = "http://www.pythontest.net/XXXinvalidXXX"
        open_url = urllib.FancyURLopener().open(URL)
        try:
            code = open_url.getcode()
        finally:
            open_url.close()
        self.assertEqual(code, 404) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_urllibnet.py

示例5: test_multiple_ftp_retrieves

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def test_multiple_ftp_retrieves(self):

        with test_support.transient_internet(self.FTP_TEST_FILE):
            try:
                for file_num in range(self.NUM_FTP_RETRIEVES):
                    with test_support.temp_dir() as td:
                        urllib.FancyURLopener().retrieve(self.FTP_TEST_FILE,
                                                         os.path.join(td, str(file_num)))
            except IOError as e:
                self.fail("Failed FTP retrieve while accessing ftp url "
                          "multiple times.\n Error message was : %s" % e) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_urllibnet.py

示例6: test_redirect_limit_independent

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def test_redirect_limit_independent(self):
        # Ticket #12923: make sure independent requests each use their
        # own retry limit.
        for i in range(urllib.FancyURLopener().maxtries):
            self.fakehttp(b'''HTTP/1.1 302 Found
Location: file://guidocomputer.athome.com:/python/license
Connection: close
''')
            try:
                self.assertRaises(IOError, urllib.urlopen,
                    "http://something")
            finally:
                self.unfakehttp() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_urllib.py

示例7: test_getcode

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def test_getcode(self):
        # test getcode() with the fancy opener to get 404 error codes
        URL = "http://www.python.org/XXXinvalidXXX"
        open_url = urllib.FancyURLopener().open(URL)
        try:
            code = open_url.getcode()
        finally:
            open_url.close()
        self.assertEqual(code, 404) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:11,代码来源:test_urllibnet.py

示例8: __init__

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def __init__(*args):
        self = args[0]
        apply(urllib.FancyURLopener.__init__, args)
        self.addheaders = [
            ('User-agent', 'Python-webchecker/%s' % __version__),
            ] 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:8,代码来源:webchecker.py

示例9: test_getcode

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def test_getcode(self):
        # test getcode() with the fancy opener to get 404 error codes
        URL = "http://www.example.com/XXXinvalidXXX"
        open_url = urllib.FancyURLopener().open(URL)
        try:
            code = open_url.getcode()
        finally:
            open_url.close()
        self.assertEqual(code, 404) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:11,代码来源:test_urllibnet.py

示例10: wsopen

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def wsopen(self, url, post, **params):
                noparam = params.pop('noparam',False)
                if noparam:
                        params = {}
                else:
                        if self.user is not None:
                                params['user'] = self.user
                        if self.password is not None:
                                params.pop('hmac', None)
                                HMAC=hmac.new(self.password)
                                for k,v in sorted(params.items()):
                                        HMAC.update("%s=%s" % (k,v))
                                params.update({'hmac':HMAC.hexdigest()})
                query = urllib.urlencode(params)
                if post:
                        body = query
                elif query:
                        url = "{}?{}".format(url, query)

                if self.debug:
                        if post:
                                print("POST:\n{}\n{!r}\n".format(url, body), file=sys.stderr)
                        else:
                                print("GET:\n{}\n".format(url), file=sys.stderr)

                class URLopener(urllib.FancyURLopener):
                        def http_error_default(self, url, fp, errcode, errmsg, headers):
                                return urllib.addinfourl(fp, headers, "http:" + url, errcode)
                try:
                        urllib._urlopener = URLopener()
                        if post:
                                resp = urllib.urlopen(url, body)
                        else:
                                resp = urllib.urlopen(url)
                except IOError as e:
                        raise WSError(url, msg=e)
                if self.debug:
                        print("RESPONSE:\n{}\n{}".format(resp.getcode(), resp.info()), file=sys.stderr)
                if resp.getcode() != 200:
                        raise WSError(url, resp.getcode(), resp.read())
                return resp 
开发者ID:alex-berard,项目名称:seq2seq,代码行数:43,代码来源:wsclient.py

示例11: test_urlopen

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def test_urlopen():
    # urllib
    url = urllib.quote('file:///bin/ls')
    urllib.urlopen(url, 'blah', 32)
    urllib.urlretrieve('file:///bin/ls', '/bin/ls2')
    opener = urllib.URLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')
    opener = urllib.FancyURLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')

    # urllib2
    handler = urllib2.HTTPBasicAuthHandler()
    handler.add_password(realm='test',
                         uri='http://mysite.com',
                         user='bob')
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)
    urllib2.urlopen('file:///bin/ls')
    urllib2.Request('file:///bin/ls')

    # Python 3
    urllib.request.urlopen('file:///bin/ls')
    urllib.request.urlretrieve('file:///bin/ls', '/bin/ls2')
    opener = urllib.request.URLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')
    opener = urllib.request.FancyURLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')

    # Six
    six.moves.urllib.request.urlopen('file:///bin/ls')
    six.moves.urllib.request.urlretrieve('file:///bin/ls', '/bin/ls2')
    opener = six.moves.urllib.request.URLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls')
    opener = six.moves.urllib.request.FancyURLopener()
    opener.open('file:///bin/ls')
    opener.retrieve('file:///bin/ls') 
开发者ID:PyCQA,项目名称:bandit,代码行数:43,代码来源:urlopen.py

示例12: SendMessage

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def SendMessage(self, message):
        """Message is string to send to user"""
        self.message = self.toHtml(message)
        num = len(self.message)+len(self.whofrom)+len(self.subject)
        if num > 110:
            return 2
        astring = 'http://www.mobile.att.net/messagecenter/pagersend.cgi?pin="'
        astring = astring + self.number
        astring = astring + '"&from="'
        astring = astring + self.whofrom
        astring = astring + '"&subject="'
        astring = astring + self.subject
        astring = astring + '"&message="'
        astring = astring + self.message
        astring = astring + '"&size="'
        astring = astring + str(num)+'"'
        #print astring
        
        myUrlclass = urllib.FancyURLopener()
        try:
            webPage = myUrlclass.open(astring)
            #print webPage
        except IOError:
            print 'webaddress failed'
            return -1
        #while 1:
        data = webPage.read(8192)
        if data:
            #print str(data)
            if string.find(str(data),"<TITLE>400 Bad Request</TITLE>") != -1:
                return 4
        else:
            return 3
        
        webPage.close()
        return 0 
开发者ID:ActiveState,项目名称:code,代码行数:38,代码来源:recipe-192400.py

示例13: main

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def main(proxy):
	
	try:# make a http HEAD request
		proxies = {'http': "http://"+proxy[:-1]}
		opener = urllib.FancyURLopener(proxies)
		opener.open("http://www.python.org")
		print "\t[+] Alive"
	except(IOError), msg: 
		if verbose == 1:
			print "\t[-] Error:",msg
		pass 
开发者ID:knightmare2600,项目名称:d4rkc0de,代码行数:13,代码来源:proxytest.py

示例14: proxtest

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import FancyURLopener [as 别名]
def proxtest(proxy):
	socket.setdefaulttimeout(5) #Set proxy timeout here
	proxies = {'http': "http://"+proxy}
	opener = urllib.FancyURLopener(proxies)
	opener.open("http://www.google.com") 
开发者ID:knightmare2600,项目名称:d4rkc0de,代码行数:7,代码来源:proxybot.py


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