python爬虫——爬取中国大学2019年排名
爬取中国大学2019年排名,并导入本地数据库 import requests import re import pymysql db = pymysql . connect ( 'localhost' , 'root' , '126315' , 'petzhang' ) cursor = db . cursor ( ) #1、分析目标网页,确定爬取的url路径,headers参数 for i in range ( 2 , 8 ) : #看网页结构,该排行榜从第2页到第7业是大学排名 #print(i) base_url = 'http://gaokao.xdf.cn/201901/10849478_{}.html' . format ( i ) headers = { 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36' } print ( base_url ) #2、发送请求 response = requests . get ( base_url , headers = headers ) response . encoding = 'utf-8' data =