-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvtech_ece_proflist.py
More file actions
73 lines (63 loc) · 1.67 KB
/
vtech_ece_proflist.py
File metadata and controls
73 lines (63 loc) · 1.67 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
from bs4 import BeautifulSoup
import urllib.request as urllib
import xlsxwriter
from importlib import reload
import sys
reload(sys)
# sys.setdefaultencoding('utf-8')
wk = xlsxwriter.Workbook('proflist.xlsx')
ws = wk.add_worksheet()
file = 'prof_list.txt'
target = open(file,'w')
url_base = "https://www.ece.vt.edu/people/faculty"
html = urllib.urlopen(''+url_base).read()
soup = BeautifulSoup(html,'html.parser')
tags_a = soup('a')
links = []
for item in tags_a:
link = str(item.get('href'))
if 'profile' in link:
links.append(link)
#target.write(item['href'].encode("utf-8"))
#target.write('\n')
#target.write('\n')
i=0
j=0
print(len(links))
for link in links:
url = link
html_basic = urllib.urlopen(''+url).read()
soup_basic = BeautifulSoup(html_basic,'html.parser')
tags_p = soup_basic('p')
ws.write(i,j,link.encode("utf-8"))
j = j + 1
for item in tags_p:
if item.get('class') is not None:
if 'sidepd-20' in str(item.get('class')[0]):
ws.write(i,j,item.text.encode("utf-8"))
j = j+1
i =i + 1
j = 0
print(i)
# for inneritem in item:
# target.write(inneritem.encode('utf-8'))
# target.write('-------------------\n--------------------')
#if 'person-key-info' in str(item.get('class')[0]):
# print item
'''
for item in links:
url = item
html_basic = urllib.urlopen(''+url).read()
soup_basic = BeautifulSoup(html_basic,'html.parser')
tags_p = soup('p')
target.write(item)
target.write('\n \n')
target.write('------------------------------------------------------')
target.write(item)
for inneritem in tags_p:
target.write(inneritem.encode('utf-8'))
target.write('\n')
target.write('\n \n \n \n \n
'''
wk.close()
target.close()