Created
March 22, 2017 14:43
-
-
Save guilhermemauro/3118420528ac8d2cc6bf45bb1fa497cc to your computer and use it in GitHub Desktop.
This file contains 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 bs4 import BeautifulSoup as bs | |
import requests, sys, re | |
from termcolor import colored | |
if len(sys.argv) < 2: | |
print colored("Falta o argumento palavra: Tente 'python main.py palavra'", 'red') | |
exit() | |
elif len(sys.argv) > 2: | |
print colored("O programa so toma apenas um argumento, o primeiro argumento sera utilizado.", 'red') | |
page = requests.get("http://dictionary.cambridge.org/us/dictionary/english/" + sys.argv[1]) | |
soup = bs(page.text, "html.parser") | |
key = 0 | |
for options in soup.find_all("div", { "class" : "di-head" }): | |
print str(key) + ' - ' + re.sub(r'[\ \n]{2,}', '', options.h2.text) | |
key += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment