前言全局说明
requests 模块 get请求和 post请求
一、get请求
import requests
url= "https://www.baidu.com"
my_headers= {
"User-Agent": "Mozilla/5.0",
"Referer": "http://baiud.com"
}
res = requests.get(url)
print(res.status_code) # 状态码
print(res.headers) # 响应头
print(res.text) # 响应体
二、post请求
import requests
url= "https://www.baidu.com"
my_headers= {
"User-Agent": "Mozilla/5.0",
"Referer": "http://baiud.com"
}
my_data={
"words": "测试内容",
"form": "Auto",
"to": "Auto",
}
res = requests.post(url, headers=my_headers, data=my_data)
print(res.json())
三、get 帮助信息
>>> help(requests.get)
Help on function get in module requests.api:
get(url, params=None, **kwargs)
Sends a GET request.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to send
in the query string for the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
>>>
四、post 帮助信息
>>> import requests
>>> help(requests.post)
Help on function post in module requests.api:
post(url, data=None, json=None, **kwargs)
Sends a POST request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
>>>
免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。
参考、来源:
2023-10-24_路飞-爬虫工作坊Day01/计划 1 2023-10-24 19-41-00-021.mp4 (1:19:00)
2023-10-24_路飞-爬虫工作坊Day01/计划 2 2023-10-24 21-11-02-878.mp4 (0:37:00)