import csv
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
import time
chrome_driver_path = r"D:\chromedriver.exe"
driver = webdriver.Chrome(service=Service(chrome_driver_path))
url = "https://www.shanghairanking.cn/rankings/bcur/2024"
driver.get(url)
name_list = []
provinces_list = []
types_list = []
scores_list = []
# driver.maximize_window()
for i in range(20):
names = driver.find_elements(By.CSS_SELECTOR, "span[data-v-2b687c30].name-cn")
for element in names:
text_content = element.text
name_list.append(text_content)
provinces = driver.find_elements(By.CSS_SELECTOR, "td[data-v-389300f0]:nth-child(3)")
for element in provinces:
text_content = element.text
provinces_list.append(text_content)
types = driver.find_elements(By.CSS_SELECTOR, "td[data-v-389300f0]:nth-child(4)")
for element in types:
text_content = element.text
types_list.append(text_content)
scores = driver.find_elements(By.CSS_SELECTOR, "td[data-v-389300f0]:nth-child(5)")
for element in scores:
text_content = element.text
scores_list.append(text_content)
next_page_button = driver.find_element(By.CSS_SELECTOR, "svg[data-icon='right']")
next_page_button.click()
time.sleep(0.2)
# for n, p, t, s in zip(name_list, provinces_list, types_list, scores_list):
# print(f"学校名:{n} 所在省市:{p} 类型:{t} 评分:{s}")
data = list(zip(name_list, provinces_list, types_list, scores_list))
csv_file_path = "university.csv"
headers = ["大学名称", "所在省市", "类型", "评分"]
with open(csv_file_path, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(headers)
for row in data:
writer.writerow(row)
祖传火箭
- 粉丝: 339
- 资源: 1
最新资源
- 知识领域+技术关键词+内容关键词+用途
- Visual Basics 脚本自动化读取文件并显示内容
- 卫星汽车检测2-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- ffmpeg-tools-2022-01-01-git-d6b2357edd.zip
- maven3.6.3 直接下载解压即可
- cf1a0-main.zip
- pf2字体文件-主要可以用于grub2的主题展示的字体
- 在 HTML、CSS 和 JavaScript 中创建调整大小和压缩图像项目
- 卫星地形检测1-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- 科学计算及关联CAE的应用A MULTI-LANGUAGE PROGRAMMING ENVIRONMENT
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈