A web scraper written in Python to extract words from https://www.urbandictionary.com/
- Python 3.8
- BeautifulSoup 4
- lxml
- PySimpleGUI (optional, if you don't want to use main.py)
cd
to the repo folder and install via pip install -r requirements.txt
command
- pretty much everything you can do through the website but without graphical interface
(except for user-related stuff like login, vote or submit new definitions)
Feature | State |
---|---|
get words from the main page | ✔️ |
search for a specific definition | ✔️ |
fetch random words | ✔️ |
get words votings | ❌ |
user log-in | ❌ |
add definitions | ❌ |
ability to vote | ❌ |
from urban_dictionary import UrbanDictionary
ud = UrbanDictionary()
word_of_the_day = ud.word
print("Today's WOTD is", word_of_the_day.name)
if ud.has_next_word:
word = ud.go_to_next_word()
print("Yesterday's WOTD was", word.name)
if ud.has_next_page:
ud.go_to_next_page()
print("Last week's WOTD was", ud.word.name, end="\n\n")
ud = UrbanDictionary("meaning of life")
# Be sure to check that there's actually a definition for that word
if ud.word is None:
print("no definition")
else:
print("Top definition for 'meaning of life' is:\n" +
ud.word.meaning, end="\n\n")
ud = UrbanDictionary(random=True)
# There's always going to be a word to get, no checks needed
print("Feeling lucky? Here's a random word:\n" +
ud.word.name + "\n" +
ud.word.example, end="\n\n")
# Let's get another random page full of random words
ud.go_to_previous_page()
print("Another random word:\n" +
ud.word.name + "\n" +
ud.word.example, end="\n\n")