base.py 文件源码

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

项目:rasp 作者: anidata 项目源码 文件源码
def get_page_source(self, url,
                        params=None,
                        headers=None):
        """Fetches the specified url.

        Attributes:
            url (str): The url of which to fetch the page source code.
            params (dict, optional): Key\:Value pairs to be converted to
                x-www-form-urlencoded url parameters_.
            headers (dict, optional): Extra headers to be merged into
                base headers for current Engine before requesting url.
        Returns:
            ``rasp.base.Webpage`` if successful

        .. _parameters: http://docs.python-requests.org/en/master/user/quickstart/#passing-parameters-in-urls
        """
        if not url:
            raise ValueError('url needs to be specified')

        if self.callback: self.callback()

        merged_headers = deepcopy(self.headers)
        if isinstance(headers, dict):
            merged_headers.update(headers)

        response = self.session.get(
            url, params=params, headers=merged_headers
        )
        return Webpage(
            url,
            source=response.text,
            headers=response.headers,
            response_code=response.status_code
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号