zbrj12345的博客

眼前路,身后身,念念不忘,必有回响。

Python-爬虫请求~requsts~post
import requests,ssl

ssl._create_default_https_context=ssl._create_unverified_context

data={
"i":"j",
"from":"AUTO",
"to":"AUTO",
"smartresult":"dict",
"client":"fanyideskweb",
"salt":"1526366213158",
"sign":"031c5d1770bdb6da92080e006c1277fb",
"doctype":"json",
"version":"2.1",
"keyfrom":"fanyi.web",
"action":"FY_BY_REALTIME",
"typoResult":"false",

}
headers={
"Accept":"application/json, text/javascript, */*; q=0.01",

"Accept-Language":"zh-CN,zh;q=0.9",
"Connection":"keep-alive",
"Content-Length":str(len(data)),
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
"Cookie":"OUTFOX_SEARCH_USER_ID=-2024838773@10.169.0.83; OUTFOX_SEARCH_USER_ID_NCOO=807868141.5217086; JSESSIONID=aaaYqgpJkkw92bnP9GInw; fanyi-ad-id=44055; fanyi-ad-closed=1; ___rl__test__cookies=1526366213148",
"Host":"fanyi.youdao.com",
"Origin":"http://fanyi.youdao.com",
"Referer":"http://fanyi.youdao.com/",
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36",
"X-Requested-With":"XMLHttpRequest",
    
}
base_url='http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
response=requests.post(base_url,data=data,headers=headers)
print(response.text)#字符串
data_obj=response.json()#字典
for key,value in data_obj.items():
    print(key,value)

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/apple/PycharmProjects/stage4/spider/2018_3_12/07requests_post.py
{"translateResult":[[{"tgt":"j","src":"j"}]],"errorCode":0,"type":"en2zh-CHS","smartResult":{"entries":["","n. 字母j\r\n"],"type":1}}
translateResult [[{'tgt': 'j', 'src': 'j'}]]
errorCode 0
type en2zh-CHS
smartResult {'entries': ['', 'n. 字母j\r\n'], 'type': 1}


Process finished with exit code 0

阅读更多
版权声明: https://blog.csdn.net/zbrj12345/article/details/80323017
文章标签: requests post
个人分类: Python3 爬虫 requsts
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Python-爬虫请求~requsts~post

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭