Skip to content

Commit

Permalink
关于post请求
Browse files Browse the repository at this point in the history
  • Loading branch information
JLUVicent committed Sep 16, 2021
1 parent df1ef74 commit df103cc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 32_requests_post请求.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@


import json
import requests
from requests.models import encode_multipart_formdata

url = 'https://fanyi.baidu.com/sug'

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36'
}

data = {
'kw': 'eye'
}

# url 请求地址
# data 请求参数
# kwargs 字典
response = requests.post(url=url, data=data, headers=headers)

content = response.text
print(content)

obj = json.loads(content)
print(obj)

# 总结:
# (1)post请求不需要编解码
# (2)post请求的参数是data
# (3)不需要请求对象的定制

0 comments on commit df103cc

Please sign in to comment.