import os
import time

from bs4 import BeautifulSoup
from selenium import webdriver

def set_download_path(driver, path):
“””
禁止下载弹窗,设置下载路径
“””
path = path.rstrip(os.sep)
driver.command_executor._commands[“send_command”] = (“POST”, ‘/session/$sessionId/chromium/send_command’)
params = {‘cmd’: ‘Page.setDownloadBehavior’,
‘params’: {‘behavior’: ‘allow’, ‘downloadPath’: path}}
driver.execute(“send_command”, params)
if not os.path.exists(path):
os.makedirs(path)

driver_path = r’C:\Users\admin\PycharmProjects\pythonProject\chromedriver.exe’ # chromedriver安装的位置

driver = webdriver.Chrome(driver_path) # 使用谷歌浏览器,加载chromedriver驱动的位置
path = ‘C:\\Users\\admin\\Desktop\\requests_pwrd’;

driver.get(‘http://localhost:8080/login’) # 请求和获取页面
page_source = driver.page_source # 获得页面的源代码
soup = BeautifulSoup(page_source, ‘html.parser’)

driver.find_element_by_name(“username”).send_keys(“admin”);
driver.find_element_by_name(“passWord”).send_keys(“admin”);

commit = driver.find_element_by_name(“commit”)
commit.click();

# 设置下载路径
# set_download_path(driver, path);
time.sleep(360) # 延迟执行360秒