Created
November 4, 2018 17:56
-
-
Save SouravJohar/ef821d570d1922e50ce07eeadb361d53 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
''' | |
Note: Using Python 2 may result in unicode errors | |
''' | |
import sys | |
import requests | |
from bs4 import BeautifulSoup as bs | |
url = "https://www.dictionary.com/browse/" | |
# read the word from the command line arguments and append to the url | |
try: | |
word = sys.argv[1] | |
url += word | |
except: | |
print("Specify a word!") | |
exit(-1) | |
# load the website's source code | |
try: | |
r = requests.get(url) | |
soup = bs(r.content, 'lxml') | |
except: | |
print("You're probably not connected to the internet!") | |
exit(-1) | |
# parse the source to obtain all necessary info | |
try: | |
header = soup.findAll("span", {"class": "luna-pos"})[0].text | |
answer_list = soup.findAll("ol")[0] | |
meanings = answer_list.findChildren("li", recursive=False) | |
except: | |
print("Word not found!") | |
exit(-1) | |
# display the results | |
print() | |
print(word + ": " + header) | |
for (i, meaning) in enumerate(meanings): | |
print() | |
print(str(i + 1) + ".", meaning.text) |
I cannot install the lxml parser
It says me to install c++ 14.0 but i already have c++ 14.28 install on my laptop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would I make this work with Python 3?