爬虫,爬中国大学排名

import requests
from bs4 import BeautifulSoup
allUniv=[]
def fillUnivList(soup):
data=soup.find_all(‘tr’)
for tr in data:
ltd=tr.find_all(‘td’)
if len(ltd)==0:
continue
singleUniv=[]
for td in ltd:
singleUniv.append(td.string)
allUniv.append(singleUniv)

r=requests.get(“http://www.zuihaodaxue.cn/zuihaodaxuepaiming2016.html”)
print(r.text)
r.encoding=“utf-8”
soup=BeautifulSoup(r.text)
print(soup)
fillUnivList(soup)
print(allUniv)

你可能感兴趣的:(Python)