pip install selenium==3.141.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn --default-timeout=100
https://registry.npmmirror.com/binary.html/?path=chromedriver/
pip install urllib3==1.26.18
from selenium import webdriver
import time
# driver = webdriver.Chrome(executable_path=r"C:\Users\Administrator\Desktop\chromedriver.exe")
driver = webdriver.Chrome()
driver.maximize_window()
keywords = [
"衡水健康科技职业学院",
"Python Selenium 教程",
"衡水天气",
"人工智能",
"衡水旅游景点"
]
# 先打开第一个页面
driver.get("https://www.baidu.com")
time.sleep(2)
for word in keywords:
url = "https://www.baidu.com/s?wd=" + word
# 新建标签页打开
driver.execute_script(f"window.open('{url}', '_blank');")
time.sleep(2)
# 保持浏览器打开,不关闭
print("全部完成,5 个标签页已打开,浏览器保持在桌面")
最后更新:2026-11-25 11:10:24 · 802 字