Skip to content

Instantly share code, notes, and snippets.

@guilhermemauro
Created March 22, 2017 14:43
Show Gist options
  • Save guilhermemauro/3118420528ac8d2cc6bf45bb1fa497cc to your computer and use it in GitHub Desktop.
Save guilhermemauro/3118420528ac8d2cc6bf45bb1fa497cc to your computer and use it in GitHub Desktop.
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