python语言爬取中国软科大学排名
以下是Python代码,可以爬取中国软科大学排名:
import requests
from bs4 import BeautifulSoup
url = 'http://www.zuihaodaxue.cn/zuihaodaxuepaiming2019.html'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
table = soup.find('tbody').find_all('tr')
for row in table:
cols = row.find_all('td')
rank = cols[0].text.strip()
name = cols[1].text.strip()
location = cols[2].text.strip()
score = cols[3].text.strip()
print(rank, name, location, score)
运行程序后,会输出所有大学的排名、名称、所在地和综合得分
原文地址: https://www.cveoy.top/t/topic/hipR 著作权归作者所有。请勿转载和采集!