学习爬虫有一段时间了,在跟着网课学习的同时自己做了一些小爬虫作为练习。
第一个是爬取中国大学排行榜的小爬虫。
网址:http://www.zuihaodaxue.cn/zuihaodaxuepaiming2016.html
import requests
from bs4 import BeautifulSoup
import bs4
def getHTMLText(url):
try:
r = requests.get(url, timeout=30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return ""
def fillUnivList(ulist, html):
soup = BeautifulSoup(