@@ -0,0 +1,1738 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0A%22%22%22%E6%9C%89%E9%81%93%E8%AF%8D%E5%85%B8.%22%22%22%0A%0Afrom urllib import quote%0Aimport re%0A%0Aimport requests%0Afrom bs4 import BeautifulSoup%0Afrom pyshanb.color import color%0A%0A%0Adef clean_text(text):%0A    %22%22%22%E6%B8%85%E7%90%86%E6%96%87%E6%9C%AC.%0A%0A    %E5%8E%BB%E6%8E%89%E9%A6%96%E5%B0%BE%E7%A9%BA%E6%A0%BC, %E5%B0%86%E5%A4%9A%E4%B8%AA%E7%A9%BA%E6%A0%BC%E5%90%88%E5%B9%B6%E4%B8%BA%E4%B8%80%E4%B8%AA, %E6%9B%BF%E6%8D%A2%E6%8D%A2%E8%A1%8C%E7%AC%A6%E4%B8%BA%E4%B8%80%E4%B8%AA%E7%A9%BA%E6%A0%BC.%0A%0A    %22%22%22%0A    text = re.sub(r'(?%3C=%5Cs)%5Cs+', '', text.strip())%0A    return re.sub(r'%5Cn', ' ', text)%0A%0A%0Adef search(word):%0A    %22%22%22%E8%A7%A3%E6%9E%90%E6%90%9C%E7%B4%A2%E7%BB%93%E6%9E%9C.%22%22%22%0A    headers = %7B%0A        'User-Agent': (' Mozilla/5.0 (Windows NT 6.2; rv:23.0) Gecko'%0A                       + '/20100101 Firefox/23.0'),%0A    %7D%0A    response = requests.get('http://dict.youdao.com/search?q=%25s' %25 quote(word),%0A                            headers=headers)%0A    if not response.ok:%0A        return%0A    html = response.text%0A    soup = BeautifulSoup(html)%0A%0A    # %E6%89%BE%E5%88%B0%E4%B8%AD%E6%96%87%E8%A7%A3%E9%87%8A%E6%89%80%E5%9C%A8%E5%9D%97%0A    phrs_list = soup.find(id='phrsListTab')%0A    if not phrs_list:%0A        return%0A    # %E8%A7%A3%E9%87%8A%0A    trans = phrs_list.find_all(class_='trans-container')%0A    tran_lists = %5B%5D%0A    addition_lists = %5B%5D%0A    for tran in trans:%0A        # %E5%9F%BA%E6%9C%AC%E8%A7%A3%E9%87%8A%0A        uls = tran.find_all('ul')%0A        for ul in uls:%0A            lis = ul.find_all('li')%0A            for li in lis:%0A                tran_lists.append(li.get_text())%0A        # %E9%99%84%E5%8A%A0%E4%BF%A1%E6%81%AF%EF%BC%9A%E5%A4%8D%E6%95%B0%EF%BC%8C%E8%BF%87%E5%8E%BB%E5%BC%8F%E3%80%82%E3%80%82%E3%80%82%0A        additionals = tran.find_all(class_='additional')%0A        for info in additionals:%0A            addition_lists.append(info.get_text())%0A    return map(clean_text, tran_lists), map(clean_text, addition_lists)%0A%0A%0Adef output(word, colour='green'):%0A    trans = search(word)%0A    word_color = color(word, colour, effect='underline')%0A    print '%5Cn' + 'youdao.com- %25s --begin'.center(40, '-') %25 word_color%0A    for tran in trans:%0A        print '%5Cn'.join(tran)%0A    print 'youdao.com------end'.center(45, '-')%0A%0A%0Aif __name__ == '__main__':%0A    output('hello')%0A

添加从有道词典获取解释的脚本.