-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
82 lines (41 loc) · 1.37 KB
/
app.py
File metadata and controls
82 lines (41 loc) · 1.37 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# importing all the required modules
import os
import requests
from bs4 import BeautifulSoup
import time
# store starting time
begin = time.time()
# asking for folder name and the range
folder_name = input("name?- ")
limit = int(input('range- '))
os.mkdir(folder_name) # making the specified folder
lnk = input("link- ") # the link to be scraped
o= requests.get(lnk).text # scraping the link
soup = BeautifulSoup(o, 'html.parser')
l = []
for i in soup.find_all("a"):
try:
if "https" not in (i['href']):
s= f"https://en.wikipedia.org{i['href']}"
l.append(s)
except:
pass
file_name = []
for i in range(0, len(l)):
file_name.append(l[i].split('/')[-1])
file_names = []
for i in file_name:
test_str = ''.join(letter for letter in i if letter.isalnum())
file_names.append(test_str)
print("done")
data = []
for i in range(0, limit):
o2 = requests.get(l[i]).text
data.append(o2)
os.chdir(folder_name)
for i in range(0, limit):
with open(f"{file_names[i]}.html",'w', encoding='utf-8') as f:
f.write(data[i])
end = time.time()
print("done !!!")
print(f"Total runtime of the program is {end - begin}") # total time taken by the script to run