对icourse、学堂在线等网页中的大学名称进行爬取:
# to clean data from icourses
fi = open("icourses.txt","r",encoding="utf-8")
ls = []
for line in fi:
if "alt" in line:
tokens = line.split('"')
uname = tokens[-2]
if "大学生" in uname:
continue
if "大学" in uname or "学院" in uname:
ls.append(uname)
print("".join(ls))
print(len(ls))
fi.close()
#to claean data from xuetangx
fi = open("xuetangx.txt","r",encoding="utf-8")
U = set() #使用集合去重
for line in fi:
if "慕课" in line:
continue
if "大学" in line or "学院" in line:
U.add(line.strip("\n"))
print("".join(U))
print(len(U))
fi.close()
# to claen data from cnmooc
fi = open("cnmooc.txt","r",encoding="utf-8")
U = set()
for line in fi:
if "大学" in line or "学院" in line:
U.add(line.strip("/n"))
print("".join(U))
print(len(U))
fi.close()
#汇总结果
ic = ''' '''
xt = ''' '''
cm = ''' '''
U =set()
U |= set(ic.split())
U |= set(xt.split())
U |= set(cm.split())
ls = list(U)
ls.sort()
print("",join(ls))
print(len(ls))