-
Notifications
You must be signed in to change notification settings - Fork 0
/
urban.py
47 lines (38 loc) · 1.25 KB
/
urban.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#imports
import requests,lxml
from lxml import html
#end imports
#globals
global trm
global finalurl
#end globals
def define(trm):
trm = parseTerm(trm)
finalurl = "https://www.urbandictionary.com/define.php?term=" + trm
pageContent=requests.get(finalurl)
tree = html.fromstring(pageContent.content)
final = tree.xpath('//*[@id="content"]/div[1]/div[3]//text()')
if "Define it!" in final:
return "[*] This term does not appear to exist on the urbandictionary site, please try a different string"
else:
finstr = ''.join(final)
#print (trm + " - " + finstr) debug testing
return finstr
def example (ex):
ex = parseTerm(ex)
finalurl = "https://www.urbandictionary.com/define.php?term=" + ex
pageContent=requests.get(finalurl)
tree = html.fromstring(pageContent.content)
final = tree.xpath('//*[@id="content"]/div[1]/div[4]//text()')
if "Define it!" in final:
return "[*] This term does not appear to exist on the urbandictionary site, please try a different string"
else:
finstr = ''.join(final)
#print ("Ex: " + finstr) debug testing
return finstr
def parseTerm(trm):
trm = trm.replace(" " , "+")
return trm
#if __name__ == "__main__": #moreeee debug testing
#define("cow")
#example("cow")