#coding = utf-8
import re #导入正则模块
import requests #导入requests模块,第三方模块需要通过pip install requests下载
for page in range(1,13): #构建循环,爬取1-13页的内容
url = “https://edu.aqniu.com/course/explore?page="+"page"
headers = {
“Proxy-Connection”: “keep-alive”,
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36”,
“Accept”: “text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8”,
“Accept-Encoding”: “gzip, deflate”,
“Accept-Language”: “zh-CN,zh;q=0.8”
} #构建headers,应对服务器防爬虫机制
r = requests.get(url=url,headers=headers)
#print(r.text)
title = re.findall(‘alt=”(.*?)” class=”img-responsive” data-echo=”‘,r.text) #利用正则模块获得re.findall(‘alt=”XXXX” class=”img-responsive” data-echo=”
print(title)