网站制作青岛公司,为什么要做外贸网站,程序员培训学费,保定企业建站程序1.安装requests
进入控制台使用该命令安装requests
pip3 install requests
2.对网站使用get请求
这里用对网站进行get请求#xff0c;然后打印。
import requests //引用requestsresponse requests.get(urlhttps://www.bilibili.com/)print(response.text)
3.对网站使用…1.安装requests
进入控制台使用该命令安装requests
pip3 install requests
2.对网站使用get请求
这里用对网站进行get请求然后打印。
import requests //引用requestsresponse requests.get(urlhttps://www.bilibili.com/)print(response.text)
3.对网站使用post请求
这里用对网站进行post请求然后打印。
import requestsdata {name,测试}
# post请求页面数据并向页面传递数据
response requests.patch(https://www.bilibili.com/);
print(response.text)
4.对网站使用get带参数的请求
import requestsdata {key1:value1,key2:value2}response requests.get(https://www.jd.com,paramsdata)print(response.url)
print(response.headers)
print(response.text)
5.获取网站的动态数据
网址可以使用浏览器的F12查询图片地址 #使用requests模块可以获得整个页面数据
#如果希望获得页面中的某一个数据改如何获取
#https://i0.hdslb.com/bfs/new_dyn/b4f40893e8c7b1f07a79f92aef9551fc3546568116406964.jpg.webpimport requests#获得图片
response requests.get(https://i0.hdslb.com/bfs/new_dyn/b4f40893e8c7b1f07a79f92aef9551fc3546568116406964.jpg.webp)
with open(tupian.webp,wb) as f:f.write(response.content)
6.获得本机ip
import requests#获得JSON
response requests.get(http://httpbin.org/ip)
data response.json()
print(data)
print(data[origin])
7. 自定义头部信息
import requests
header{user-agent:haha/v
}
response requests.get(http://httpbin.org/get,headers header)
print(response.headers)#获得请求头信息
print(response.request.headers)#获得响应头信息
8.查看coolkies_arg
import requestsurl http://httpbin.org/cookies
cookies dict(coolkies_arghello python)
response requests.get(urlurl,cookiescookies)
print(response.text) 9.如何查看网站头部
1.访问网站打开发F12这里使用百度演示 2.点击网络选项刷新页面 3.找到该文件一般在第一个的位置点击查看信息 最后一样就是我们需要的信息。