Python爬录取分数线
时间: 2023-11-29 13:44:30 浏览: 167
以下是Python爬取历年高考录取分数线的示例代码:
```python
import requests
from bs4 import BeautifulSoup
# 请求URL
url = 'https://gkcx.eol.cn/schoolhtm/schoolAreaPoint/10032/10056/10057/10058.htm'
# 发送请求
response = requests.get(url)
# 解析HTML
soup = BeautifulSoup(response.text, 'html.parser')
# 获取表格
table = soup.find('table', class_='scores_List')
# 获取表头
thead = table.find('thead')
ths = thead.find_all('th')
headers = [th.text.strip() for th in ths]
# 获取表格数据
tbody = table.find('tbody')
trs = tbody.find_all('tr')
data = []
for tr in trs:
tds = tr.find_all('td')
row = [td.text.strip() for td in tds]
data.append(row)
# 输出表格数据
for row in data:
print(row)
```
该代码使用requests库发送请求,使用BeautifulSoup库解析HTML,获取历年高考录取分数线的表格数据,并输出到控制台。
阅读全文