zoukankan      html  css  js  c++  java
  • 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()
    
  • 相关阅读:
    学习进度笔记06
    学习进度笔记05
    学习进度笔记04
    学习进度笔记03
    学习进度笔记02
    周总结13
    周总结12
    周总结11
    人月神话阅读笔记3
    第一阶段冲刺10
  • 原文地址:https://www.cnblogs.com/laresh/p/6696153.html
Copyright © 2011-2022 走看看