本帖最后由 pcl_test 于 2017-5-26 21:27 编辑
https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/- # encoding: utf-8
- # Python 3.6.0
- import requests
- from bs4 import BeautifulSoup
-
- def trans(str):
- html=requests.post("http://dict.youdao.com/search?q="+str).content
- text=str+'\r\n'
- if html:
- soup = BeautifulSoup(html,"html.parser")
- container = soup.find("div", attrs={"class": "trans-container"})
- lis = container.find_all('li')
- authDictTrans = lis[0].find_all("span", attrs={"class": "def"})
- if authDictTrans:
- for span in authDictTrans:
- text+=span.string+'\r\n'
- else:
- for li in lis:
- text+=li.string+'\r\n'
- return text
-
- str='look like,feel like,something like,if you like,nothing like,anything like,like as,like a dream,like anything,such like,like to do,like crazy,like what,like mad,like it or not,like hell,likes and dislikes,make like,or the like,like nothing on earth'
- for kw in str.split(','):
- print(trans(kw))
复制代码
|