1、get請求:requests不帶引數模擬
import requests
response=requests.get(url='請求位址') #get()方法傳送get請求
#方式一:
print(response.content.decode('utf-8')) #列印response,並轉碼為utf-8
#方式二:
response.encode='utf-8'
print(response.text)
2、get請求:requests帶引數模擬
import requests
#方式一:
response1=requests.get(url='請求位址+引數') #get()方法傳送get請求
print(response1.content.decode('utf-8')) #列印response,並轉碼為utf-8
#方式二:
#設定乙個引數字典
dict_params= {
"key1":"value1",
"key2":"value2",
response2=requests.get(url='請求位址', params=dict_params) #get()方法傳送get請求
print(response2.content.decode('utf-8')) #列印response,並轉碼為utf-8
3、get請求:requests帶head引數模擬
import requests
#設定乙個引數字典
headers={
dict_params= {
"key1":"value1",
"key2":"value2",
response=requests.get(url='請求位址', params=dict_params, headers=headers) #get()方法傳送get請求
print(response.content.decode('utf-8')) #列印response,並轉碼為utf-8
4、json資料轉換
json.dumps() #將字典格式轉換為字串格式
json.loads() #將字串格式轉換為字典/json格式
5、post請求:requests帶head引數模擬
response=requests.post(url='請求位址', params=dict_params, json=json) #post()方法傳送post請求
response=requests.post(url='請求位址', params=dict_params, data=json.dumps(json)) #data中需要帶字串
print(response.content.decode('utf-8')) #列印response,並轉碼為utf-8
2、get請求:requests帶引數模擬
import requests
#方式一:
response1=requests.get(url='請求位址+引數') #get()方法傳送get請求
print(response1.content.decode('utf-8')) #列印response,並轉碼為utf-8
#方式二:
#設定乙個引數字典
dict_params= {
"key1":"value1",
"key2":"value2",
response2=requests.get(url='請求位址', params=dict_params) #get()方法傳送get請求
print(response2.content.decode('utf-8')) #列印response,並轉碼為utf-8
git常用操作 持續更新中
這個圖是在乙個人的部落格上找到的,侵刪!git push f orgin master 強制提交 git fetch all 強制覆蓋本地 git reset hard origin master git merge git pull origin master 拉取遠端倉庫專案 gitrm r c...
MySQL FAQs (持續更新中)
windows下為my.ini linux下在 etc my.cnf,還可以通過命令 whereis my查詢 剛裝完以root登入時有可能報這樣的錯 error 2002 hy000 can t connect to local mysql server through socket var li...
linux常用操作,持續更新。。。。
1.修改主機名 hostname 臨時生效,修改後重啟系統失效 hostnamectl set hostname 永久生效,重啟後依然有效2.防火牆命令 systemctl status firewall.service 檢視防火牆狀態 systemctl stop firewall.service...