python Demo 01 爬取大学名称

对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))

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值