Fork me on GitHub

青禹小生

雁驰万里却作禽,鱼未得水空有鳞。 花开花落花不语,昨是昨非昨亦今。

导航

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()

 

posted on 2017-04-11 20:32  司徒道  阅读(1163)  评论(0编辑  收藏  举报