A Simple network dictionary written by Python:python

Source: Internet
Author: User

Nothing to do, play python ...

is to use Youdao translation, and then crawl the Web page.

Import Re, urllib url= "http://dict.youdao.com/search?le=eng&q=" Print ("Input Q to Exit") while 1:word = Raw_input ("& Gt;>> ") If word==" Q ": Exit () Else:word = Word.replace (', ' + ') URL + + Word url =" &tab=chn&keyfrom=dict.t " Op "s = Urllib.urlopen (URL). Read () comm1 = Re.compile ('; </td><td class= ' attributem1web ' >.*?</td> ') Result=comm1.findall (s) comm2 = Re.compile (R ' <td class= "dttitle2" ><font color= "#013694" ><b>.*? <//b><//font><//td> ') Related = Comm2.findall (s) #find the result if result:print ' meaning: ' to I in R Esult:temp = I.decode (' UTF8 '). Encode (' cp936 ') temp = temp[33:] temp = temp[:-5] Print temp print ' n ' #fine the matters I F related:print ' Related: ' for i in related:temp = I.decode (' UTF8 '). Encode (' cp936 ') temp = temp[46:] temp = temp[:-16] P Rint temp print '/n ' else:print ' no such word! '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.