学习内容
(1)正则表达式:re
------- 用于提取有用的文本信息
--------常用的有(.*?)、(https://.*?.jpg)、(https://.*?.mp3)
--------常用指令re.compile()、re.findall()
(2)requests请求
--------通过requests.get/post(url,headers)获取网页信息或者文件
简单实例:
import re
import requests
i=0
for x in range(100):
url = 'http://acm.zzuli.edu.cn/ranklist.php?start='+str(i)
findlink = re.compile(r"user=.*?</a></div></td><td> <div class=center>(.*?)</div></td><td> <div class=center><a href='status.php")
findlink2 = re.compile(r"<div class=center><a href='status.php.*?'>(.*?)</a></div></td><td> <div class=center><a href='status.php")
html = requests.get(url).text
names = re.findall(findlink, html)
numbers = re.findall(findlink2,html)
z=0
for name in names:
i += 1
print("第", i, "名:", name," 正确:",numbers[z])
z+=1