python 输入英语单词,查看汉语意思

# -*- coding:utf-8 -*-
import urllib2
import lxml.html as HTML

def get_wordmean():
    url = 'http://www.iciba.com/'
    search = raw_input('search:')
    url += search
    headers = {'User-Agent':'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
    req = urllib2.Request(url, headers=headers)
    content = urllib2.urlopen(req).read()
    if isinstance(content, unicode):
        pass
    else:
        content = content.decode('utf-8')
    htmlSource = HTML.fromstring(content)
    prop = htmlSource.xpath(r"//span[@class='prop']/text()|//li[@class='clearfix']/p/span/text()")
    if prop:
        for i in prop:
            print i
    else:
        print 'please input correct word!'

if __name__ == "__main__":
    get_wordmean()
原文地址:https://www.cnblogs.com/laresh/p/6696153.html