直接上代码
UK和US分别保存,有道的源
import requests
def voice(name):
url='https://dict.youdao.com/dictvoice'
data = {'audio':name,"type":1}
headers ={"User-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:36.0) Gecko/20100101 Firefox/36.0",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language":"en-US,en;q=0.5",
"Accept-Encoding":"gzip, deflate",
"Connection":"keep-alive",
"Content-Type":"application/x-www-form-urlencoded",
}
resp = requests.get(url, headers=headers,params=data)
with open('UK.mp3','wb') as f:
f.write(resp.content)
data = {'audio':name,"type":2}
resp = requests.get(url, headers=headers,params=data)
with open('US.mp3','wb') as f:
f.write(resp.content)
voice('name')