repl.it
@notbehind_you/

dictionary.nyoom

Python

No description

fork
loading
Files
  • main.py
main.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
48
import requests, lxml
from lxml import html
from bs4 import BeautifulSoup
###############################
#//*[@id="content"]/div[1]/div[2]/div/div/div/div[1]/section[1]/ul/li[2]/div/p/span[3]
#//*[@id="content"]/div[1]/div[2]/div/div/div/div[1]/section[1]/ul/li[3]/div/p/span[3]
#//*[@id="content"]/div[1]/div[2]/div/div/div/div[1]/section[1]/ul/li[1]/div/ol/li[1]/span[2]
x = """
oxford_url = "https://en.oxforddictionaries.com/definition/leg"
li_xpath = "//*[@id='content']/div[1]/div[2]/div/div/div/div[1]/section[1]/ul/li[2]/div/p/span[3]/text()"
pageContent = requests.get(oxford_url, headers={'User-agent': 'human'})
tree = html.fromstring(pageContent.content)
data= tree.xpath(li_xpath)
finstr = ''.join(data)
print (finstr)
"""


finalurl = "https://en.oxforddictionaries.com/definition/egg"#the percent gets us to the gallary home, and then the 1 gets us to the first page.
pageContent = requests.get(finalurl, headers={'User-agent': 'human74'})
data = pageContent.text
soup = BeautifulSoup(
    data, "lxml"
)  #We use beautiful soup here instead of requests, as it allows us to grab the inside elements.

listt = []
butno = 0  #it returns 2 values every time so we use a value like this to only get the second
for link in soup.find_all('p'):
	print (link)

#//*[@id='content']/div[1]/div[2]/div/div/div/div[1]/section[1]/ul/li[1]/div/p/span[3]/text()


#You can parse out the contextual topic of each of the words from the begining, compare string should be a way to do it.

stuffGotten = """
<p><span class="iteration">1</span><span class="ind">Each of the limbs on which a person or animal walks and stands.</span></p>
<p><span class="iteration">2</span><span class="ind">Each of the supports of a chair, table, or other structure.</span></p>
<p><span class="iteration">3</span><span class="ind">Asection or stage of a journey or process.</span></p>
<p><span class="iteration">4</span><span class="ind">Abranch of a forked object.</span></p>
<p><span class="iteration">5</span><span class="sense-regions domain_labels">Cricket </span><br/><span class="ind">The half of the field (as divided lengthways through the pitch) away from which the batsman's feet are pointed when standing to receive the ball.</span></p>
<p><span class="iteration">6</span><span class="sense-registers">archaic </span><span class="ind">A deferential gesture made by drawing back one leg and bending it while keeping the front leg straight.</span></p>

<p><span class="iteration">1</span><span class="ind">An oval or round object laid by a female bird, reptile, fish, or invertebrate, usually containing adeveloping embryo. The eggs of birds are enclosed in a chalky shell, while those of reptiles are in aleathery membrane.</span></p>
<p><span class="iteration">2</span><span class="sense-regions domain_labels">Biology </span><br/><span class="ind">The female reproductive cell in animals and plants; an ovum.</span></p>
<p><span class="iteration">3</span><span class="sense-regions domain_labels">Architecture </span><br/><span class="ind">A decorative oval moulding, usedalternately with triangular shapes.</span></p>
<p><span class="iteration">4</span><span class="sense-registers">dated, informal </span><span class="grammatical_note">with adjective</span> <span class="ind">A person of a specified kind.</span></p>
"""
Fetching token
?