summaryrefslogtreecommitdiff
path: root/Scripts/wiki2P.py
blob: 316c7e96cd0ee32b39c8163e95d3cfb56f4bb931 (plain)
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
import requests, bs4, re




def calculate(site):

        print("Downloading wikipedia site: " + site)


        res = requests.get("https://en.wikipedia.org" + site)

        print("Download completed analysing")

        soup = bs4.BeautifulSoup(res.text, "html.parser")


        element = soup.find("div", {"class": "mw-content-ltr"}).find("p")


        #print(element)

        elements = element.find_all("a")




        pattern = re.compile("\/wiki\/(?!File|Help).*")

        results = ""


        for i in elements:
                if pattern.match(i["href"]) :
                        results = i["href"]
                        break

        return results



siter = "/wiki/Linux"

while siter is not "philosophy":
        input(siter)
        siter = calculate(siter)