GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python/Dict.py at master · codefar/Python

Expand file tree

/

Dict.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
28 lines (23 loc) · 906 Bytes
/

Dict.py

Copy path

File metadata and controls

executable file
·
28 lines (23 loc) · 906 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python
#coding:utf-8
import urllib
import sys
import re
if len(sys.argv) == 1: #没有单词就提示用法
print "用法:./Dict.py 要查找的单词"
sys.exit()
word = ""
for x in range(len(sys.argv) - 1): #查找的可能是短语,中间有空格,如"join in",这里拼接单词
word += " " + sys.argv[x + 1]
print "单词:" + word
searchUrl = "http://dict.youdao.com/search?q=" + word + "&keyfrom=dict.index" #查找的地址
response = urllib.urlopen(searchUrl).read() #获得查找到的网页源码
#从网页源码提取出单词释义那一部分
searchSuccess = re.search(r"(?s)<div class=\"trans-container\">\s*<ul>.*?</div>",response)
if searchSuccess:
means = re.findall(r"(?m)<li>(.*?)</li>",searchSuccess.group()) #获取我们想提取的核心单词释义
print "释义:"
for mean in means:
print "\t" + mean #输出释义
else:
print "未查找到释义."
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.