-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiit_bombay.py
70 lines (37 loc) · 1.3 KB
/
iit_bombay.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
61
62
63
64
65
66
67
68
69
70
import aiohttp
import asyncio
import bs4
import re
from pandas import read_excel
import time
from function import *
link = "https://www.ieor.iitb.ac.in/people/research_scholars"
async def fetch_all_data(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
# name = url[to_cut:]
status = response.status
response = await response.text()
if status == 429:
print("too many request to server , error code : 429")
# if verbose:
# print(response, status)
soup = bs4.BeautifulSoup(response , 'html.parser')
name = soup.find("div" , {'class' : 'field-item even'})
text = name.find_all('a')
name_list = []
for t in text:
name_list.append([str(t.get_text()) ,t['href'] ])
print(name_list)
def print_all_pages():
tasks = []
loop = asyncio.new_event_loop()
try:
tasks.append(loop.create_task(fetch_all_data(link)))
loop.run_until_complete(asyncio.wait(tasks))
except KeyboardInterrupt:
print("Program Terminated by User")
print("<---Bye--->")
loop.close()
# close_file(f)
print_all_pages()