-
Notifications
You must be signed in to change notification settings - Fork 6
/
word_does_not_exist.py
32 lines (21 loc) · 883 Bytes
/
word_does_not_exist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
from bs4 import BeautifulSoup
import json
def this_word_does_not_exist():
URL = "https://www.thisworddoesnotexist.com/"
content = requests.get(URL).content.decode("utf-8")
soup = BeautifulSoup(content, "html.parser")
text = str(soup("script")[2])
data_dict = eval(json.loads(json.dumps(text[101:text.index("permalink") - 5].replace("\\", "").replace("null", "None").replace("true", "True").replace("false", "False").replace('"', '\''))))
word = data_dict['word'].capitalize()
definition = data_dict['definition'].capitalize()
example = data_dict['example'].capitalize()
exists = data_dict['probably_exists'] == True
return {
'word' : word,
'definition' : definition,
'example' : example,
'exists' : exists
}
if __name__ == '__main__':
print(this_word_does_not_exist())