中国大学排名定向爬虫(一)
话不多说,直接放码
代码很粗糙,还没有优化,而且有一个很有意思的问题没有解决,http://www.zuihaodaxue.cn/zuihaodaxuepaiming2017.html和http://www.zuihaodaxue.cn/zuihaodaxuepaiming2016.html页面完全一模一样,代码同样可以运行,但是在处理2017排名时,写入的第一列数据排名全部为None,很奇怪,还没解决,未完待续。
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 15 20:59:32 2017
@author: 刘翔
中国大学排行榜定向爬虫编写,以“最好大学网”为爬取目标,使用BeautifulSoup库
"""
import requests
from bs4 import BeautifulSoup
import bs4
def getHTMLText(url):
try:
r = requests.get(url,timeout = 30)