request.py 文件源码

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

项目:pyload-requests 作者: pyload 项目源码 文件源码
def load(self, url, get={}, post={}, referer=True, cookies=True,
             just_header=False, multipart=False, decode=False):
        """
        Load and returns a given page.
        """
        self.set_request_context(url, get, post, referer, cookies, multipart)

        # TODO: use http/rfc message instead
        self.header = ""

        if "header" in self.options:
            # TODO
            # print("custom header not implemented")
            self.setopt(pycurl.HTTPHEADER, self.options['header'])

        if just_header:
            self.setopt(pycurl.FOLLOWLOCATION, 0)
            self.setopt(pycurl.NOBODY, 1)  # TODO: nobody= no post?

            # overwrite HEAD request, we want a common request type
            if post:
                self.setopt(pycurl.CUSTOMREQUEST, 'POST')
            else:
                self.setopt(pycurl.CUSTOMREQUEST, 'GET')

            try:
                self.c.perform()
                rep = self.header
            finally:
                self.setopt(pycurl.FOLLOWLOCATION, 1)
                self.setopt(pycurl.NOBODY, 0)
                self.unsetopt(pycurl.CUSTOMREQUEST)

        else:
            self.c.perform()
            rep = self.get_response()

        self.setopt(pycurl.POSTFIELDS, '')
        self.last_url = safequote(url)
        self.last_effective_url = self.c.getinfo(pycurl.EFFECTIVE_URL)
        if self.last_effective_url:
            self.last_url = self.last_effective_url
        self.code = self.verify_header()

        if cookies:
            self.parse_cookies()

        if decode:
            rep = self.decode_response(rep)

        return rep
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号