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
)
评论列表
文章目录