Last active
June 4, 2016 05:36
-
-
Save hungtatai/aa18103b81224ba8b906727c5367a982 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.request import urlopen | |
import bs4 | |
while True: | |
word = input("Please type your word here: ") | |
html = urlopen("https://tw.dictionary.search.yahoo.com/search?p=%s" % word).read().decode("utf-8") | |
bs = bs4.BeautifulSoup(html, "html.parser") | |
explainArea = bs.select(".explain.DictionaryResults")[0] | |
wordClassList = explainArea.select(".compTitle") | |
wordExplainsList = explainArea.select(".compArticleList") | |
for i in range(len(wordClassList)): | |
wordClass = wordClassList[i].getText() | |
wordExplains = [h4.getText() for h4 in wordExplainsList[i].select("h4")] | |
print(wordClass) | |
for exp in wordExplains: | |
print(" " + exp) | |
print() | |
''' | |
Please type your word here: clever | |
a.形容詞 | |
1. 聰明的,伶俐的 | |
2. 靈巧的,熟練的,擅長的[(+with/at)] | |
3. 機敏的,巧妙的 | |
4. 【口】【貶】小聰明的 | |
Please type your word here: damn | |
vt.及物動詞 | |
1. 罰……入地獄 | |
2. 罵……該死,咒罵 | |
3. 指責,罵……一文不值 | |
4. 使失敗,毀掉 | |
n.名詞 | |
1. 詛咒[C] | |
2. 絲毫,一點點[S] | |
int.感歎詞 | |
1. 該死;討厭 | |
a.形容詞 | |
1. 【口】該死的,糟透的;完全的,十足的 | |
ad.副詞 | |
1. 【口】完全地,非常 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment