__Threading.py 文件源码

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

项目:-scrapy- 作者: PyCN 项目源码 文件源码
def post_url(self, url, formdata, headers, cookie):
        if not isinstance(url, str):
            raise 'url must be a string and fordata must be a dict'
        data = urllib.urlencode(formdata)
        req = urllib2.Request(url, data, headers)
        try:
            if not isinstance(cookie, cookielib.CookieJar) and cookie is None:
                response = urllib2.urlopen(req)
            elif not isinstance(cookie, cookielib.CookieJar) and cookie is not None:
                cookie = cookielib.CookieJar()
                handler = urllib2.HTTPCookieProcessor(cookie)
                opener = urllib2.build_opener(handler)
                response = opener.open(req)
            elif isinstance(cookie, cookielib.CookieJar):
                handler = urllib2.HTTPCookieProcessor(cookie)
                opener = urllib2.build_opener(handler)
                response = opener.open(req)

        except urllib2.HTTPError:
            raise 'get url error!!'
        the_page = response.read()

        return the_page, cookie
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号