button 标签 回车登录出错

博客介绍了通过修改button的type属性为button,来解决button在回车后默认触发点击事件的问题,属于前端开发范畴。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

修改button type=”button” 解决button回车后默认触发点击事件问题。

``` from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.chrome.options import Options import time import os os.system(r'start chrome --remote-debugging-port=8082 --user-data-dir="F:\selenium"') # 等待接管页面(也就是说首先需要手动登录账号以及搜索需要的文献) input('输入回车继续程序...') options = Options() options.add_experimental_option("debuggerAddress", "127.0.0.1:8082") driver = webdriver.Chrome(options=options) print(driver.title) print("#######") refrences = 0 while True: # 等待页面加载完成 WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'gs_r'))) time.sleep(4) #如果时不时有文献没有被保存可以尝试将这个数值加大 # 获取每篇文章的信息 articles = driver.find_elements(By.CLASS_NAME, 'gs_r') # 如果没有下一页,退出循环 if not articles: break # 遍历每篇文章 i = 0 for article in articles: i += 1 if i==11: break # 获取保存按钮 save_button = article.find_element(By.CLASS_NAME, 'gs_or_sav') print(save_button) # 点击保存按钮 if save_button: try: save_button.click() # 等待一段时间确保弹出的选择框加载完成 time.sleep(2) # 获取完成按钮并点击 complete_button = driver.find_element(By.ID, 'gs_lbd_apl') # time.sleep(3000) if complete_button: complete_button.click() except Exception as e: print(f"Error clicking save button: {e}") refrences += i-1 print(f"{refrences} refrences have been saved") print("next page") next_page = driver.find_element(By.CLASS_NAME, 'gs_ico_nav_next') next_page.click() # 关闭浏览器 driver.quit()```请解释这个代码的内容,能实现的功能
最新发布
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值