爬取‘排名’,‘校名’,‘省市’,‘总分’,这四个字段信息(只需要前30条数据) 【网页地址为:https://www.shanghairanking.cn/rankings/bcur/202411】
时间: 2024-06-17 08:05:01 浏览: 106
您好,您可以使用 Python 中的 requests 库和 BeautifulSoup 库来爬取该网页的信息。具体步骤如下:
1. 使用 requests 库发送 GET 请求获取网页内容。
2. 使用 BeautifulSoup 库解析网页内容,找到包含所需信息的标签。
3. 提取每个学校的‘排名’,‘校名’,‘省市’,‘总分’四个字段信息,只需要前30条数据。
下面是示例代码:
```
import requests
from bs4 import BeautifulSoup
url = 'https://www.shanghairanking.cn/rankings/bcur/202411'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
table = soup.find('table', class_='rk-table')
tbody = table.tbody
rows = tbody.find_all('tr')
for row in rows[:30]:
cols = row.find_all('td')
rank = cols.text.strip()
name = cols.text.strip()
location = cols[2].text.strip()
score = cols.text.strip()
print(rank, name, location, score)
```
阅读全文
相关推荐

















