日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Post方式之百度翻译的爬取

發(fā)布時(shí)間:2024/6/30 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Post方式之百度翻译的爬取 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
from urllib import request,parse
import json

# 翻譯函數(shù)
def fanyi(msg):

#參數(shù)封裝
data = {
"kw": content
}

#參數(shù)拼接以及轉(zhuǎn)碼
data = parse.urlencode(data)

#請(qǐng)求地址
base_url = "http://fanyi.baidu.com/sug"

# Post
headers = {
"Content-Length": len(data), #動(dòng)態(tài)計(jì)算d··ata長度
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"
}

#封裝一個(gè)request對(duì)象(地址,數(shù)據(jù),headers)
req = request.Request(url=base_url, data=bytes(data, encoding="utf-8"), headers=headers)

#發(fā)起請(qǐng)求,并得到響應(yīng)
response = request.urlopen(req)

#讀取內(nèi)容
html = response.read()
html = html.decode("utf-8") #轉(zhuǎn)碼

json_data = json.loads(html)#使用json格式化
#print(json_data)

# 整理數(shù)據(jù)
for item in json_data["data"]:
print(item["k"], item["v"])

if __name__ == "__main__":
#輸入數(shù)據(jù)
content = input("請(qǐng)輸入您要翻譯的內(nèi)容:")

#翻譯
fanyi(content)
# https://tbmsg.baidu.com/gmessage/get?mtype=1&_=1521032999727
# https://tieba.baidu.com/f?kw=qq%E7%82%AB%E8%88%9E%E6%89%8B%E6%B8%B8&ie=utf-8&pn=50

轉(zhuǎn)載于:https://www.cnblogs.com/cuihengyue/p/8714584.html

與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的Post方式之百度翻译的爬取的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。