urllib 中的post请求

import urllib.request
import urllib.parse

url = 'http://fanyi.baidu.com/v2transapi'

word = 'meizi'

formdata = {
'from' : 'en',
'to' : 'zh',
'query':word,
'transtype':'realtime',
'simple_means_flag' :'3',
'sign': '800673.578704',
'token' :'b4af6d5be2544feca4407f376e0b5635'
}

headers = {
'Host': 'fanyi.baidu.com',
# 'Connection': 'keep-alive',
# 'Content-Length': '135',
# 'Accept': '*/*',
'Origin': 'http://fanyi.baidu.com',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent':' Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36',
# 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'http://fanyi.baidu.com/translate?aldtype=16047',
# 'Accept-Encoding': 'gzip, deflate',
'Accept-Language':' zh-CN,zh;q=0.9',
'Cookie': 'REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; PSTM=1526888660; BIDUPSID=3AC4D74B022A729BF6F805111B8EDE9A; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BAIDUID=6B0F99164495B82513E4B8AD44956B6A:FG=1; H_PS_PSSID=26357_1465_21093_20928; PSINO=1; locale=zh; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1527585078,1527585086,1527585119,1527592236; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1527592236; to_lang_often=%5B%7B%22value%22%3A%22zh%22%2C%22text%22%3A%22%u4E2D%u6587%22%7D%2C%7B%22value%22%3A%22en%22%2C%22text%22%3A%22%u82F1%u8BED%22%7D%5D; from_lang_often=%5B%7B%22value%22%3A%22pt%22%2C%22text%22%3A%22%u8461%u8404%u7259%u8BED%22%7D%2C%7B%22value%22%3A%22en%22%2C%22text%22%3A%22%u82F1%u8BED%22%7D%2C%7B%22value%22%3A%22zh%22%2C%22text%22%3A%22%u4E2D%u6587%22%7D%5D',

}


request = urllib.request.Request(url=url,headers=headers)

formdata = urllib.parse.urlencode(formdata).encode()


response = urllib.request.urlopen(request,formdata)

print(response.read().decode())

转载于:https://www.cnblogs.com/airapple/p/9132002.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值