-
Notifications
You must be signed in to change notification settings - Fork 0
/
wikipedia data scraper.py
60 lines (43 loc) · 1.46 KB
/
wikipedia data scraper.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
49
50
51
52
53
54
55
56
57
58
59
60
from tkinter import *
from tkinter import ttk
import requests
from bs4 import BeautifulSoup
app = Tk()
app.title("Wikipedia Data Scraper")
app.geometry("800x700")
style = ttk.Style()
style.map("C.TButton",
foreground=[('pressed', 'green'), ('active', 'blue')],
background=[('pressed', '!disabled', 'black'), ('active', 'white')]
)
label = Label(app,
text = "WIKISCRAPA",
foreground= 'black', font=('Perpetua', 15))
# label.grid(row = 0, column=0)
label.pack()
search_text = StringVar()
text = Entry(app, textvariable=search_text, font= 'Kalinga')
# text.grid(row=0, column= 2)
text.focus_set()
text.pack()
button = ttk.Button(app, text = 'Search Wiki', width = 12, style = "C.TButton", command= lambda:search_wiki(search_text.get()))
button.pack(side = TOP)
# button.grid(row=1, column=2)
text_area = Text(app, height = 30, width= 70, border= 10, font= ('Euphemia', 10))
# text_area.grid(row = 2, column=2)
scrollbar = Scrollbar(app)
scrollbar.pack(side=RIGHT, fill=Y)
text_area.pack(side=TOP, fill=Y)
text_area.configure(yscrollcommand= scrollbar.set)
scrollbar.configure(command = text_area.yview)
def search_wiki(search_text):
text_area.delete("1.0","end")
url = f"https://en.wikipedia.org/wiki/{search_text}"
req = requests.get(url)
html_content = req.content
text = BeautifulSoup(html_content, 'html.parser')
text_area.delete("1.0","end")
for x in text.find_all('p'):
text_area.insert( END, x.get_text())
if __name__ == "__main__":
app.mainloop()