* coding : utf-8 *
@Time : 2021/12/14 18:11
@Author : Harken
import requests
url = ‘http://fanyi.baidu.com/sug’
headers = {
‘User-Agent’: ’ Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36’
}
data = {
‘kw’:‘eye’
}
# url;data;json kwargs 字典
response = requests.post(url=url,data=data,headers=headers)
content = requests.text
import json
object = json.load(content,encoding = ‘utf-8’)
print(object)
代理
import requests url = ‘http://fanyi.baidu.com/s’
headers = { ‘User-Agent’: ’ Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36’ }
data = { ‘wd’:‘ip’ }
proxy = { ‘http’:‘121.230.210.31:3256’ }
response = requests.post(url=url,data=data,headers=headers,proxys=proxy )
content = response.text
with open(‘daili.html’,‘w’,encoding=‘utf-8’)as fp: fp.write(content)
|