?1.get 请求
# coding:utf-8
import requests
query = input("请输入")
url = f'https://www.opticres.com/Search/index.html?keyword={query}'
dic = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
}
resp = requests.get(url, headers=dic)
print(resp)
print(resp.text)
2.post 请求
# coding:utf-8
import requests
url = "https://fanyi.baidu.com/sug"
s = input("请输入你要翻译的英文")
dat = {
"kw": s,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
}
# 发送post 请求
resp = requests.post(url, data=dat)
print(resp.json())
#关掉访问
resp.close()
|