springenwerk.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:darkc0de-old-stuff 作者: tuwid 项目源码 文件源码
def getURLContents(self, url, data=None):    
        "Returns the contents of the given URL as an Unicode string" 

        s = ""
        success = False

        req = Request(url, data, {'User-agent': self.useragent})

        try:
            f = urlopen(req)  
            s = f.read()
            f.close()
            success = True
        except HTTPError, e:
            print 'Server error: ', e.code
            if (self.verbose and BaseHTTPRequestHandler.responses.has_key(e.code)):
                title, msg = BaseHTTPRequestHandler.responses[e.code]            
                print title + ": " + msg
        except URLError, e:
            print 'Connection error: ', e.reason

        dammit = UnicodeDammit(s)    

        return (success, dammit.unicode)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号