Python爬取学校教务处的通知
以西南大学为例,爬取西南大学教务处的相关通知
- 去网上搜索西南大学教务处的官网
- 爬取每个信息的标题和网址
import urllib.request
import re
from lxml import html
etree=html.etree
url1=r'http://jwc.swu.edu.cn'
res=urllib.request.urlopen(url1).read()
response=res.decode('utf-8')
# target="_blank" title="孙红举副教授获教育部 国家语委“中国语言资源保护奖”先进个人称号">
# <a href="/s/jwc/jwxx/20200318/4043479.html"
pat1=r'target="_blank" title="(.*?)">'
result1=re.compile(pat1,re.I)
data1=result1.findall(response)
result2=etree.HTML(response)
data2=result2.xpath('//li[@class="clearfix"]/p/a/@href')
# print(response)
for i in range(0,len(data1)):
fullurl=url1+data2[i]
print(i+1,'主题:',data1[i],'网址:',fullurl)
- 运行程序
- 点击任意一个网址,查看结果