使用chromedriver:javascript void(0)进行python数据爬行

2024-09-30 01:26:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用chrome驱动程序单击此登录按钮。 它不会返回错误,但没有单击按钮,每次运行代码时,我都会在网页左侧看到一个小符号,上面写着“javascript:void(0);”

这是我的密码。 提前谢谢

import os
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path="/Users/XXX/Documents/chromedriver")
driver.get('https://www.hometax.go.kr/websquare/websquare.html?w2xPath=/ui/pp/index.xml')
driver.implicitly_wait(3)

driver.find_element_by_xpath(
    '//*[@class="w2group "]'
    ).click()

enter image description here


Tags: 代码fromimportui网页supportbydriver
1条回答
网友
1楼 · 发布于 2024-09-30 01:26:15

请试一试

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


driver = webdriver.Chrome(executable_path="YOUR_CHROMEDRIVER_PATH")
driver.get('https://www.hometax.go.kr/websquare/websquare.html?w2xPath=/ui/pp/index.xml')

TARGET = 'textbox81212912'

# driver.find_element_by_id("textbox81212912").click()

element = WebDriverWait(driver, 30).until(
    EC.presence_of_element_located((By.ID, TARGET))
)
element.click()

input() # wait

首先,通过//*[@class="w2group "]选择了错误的对象 此XPath表示选择了该页面的类属性为“w2group”的所有对象中的第一个

此外,还包括“的id”로그인" 元素是:“textbox81212912”
enter image description here

其次,使用显式等待目标元素而不是隐式等待。这有助于防止意外错误,例如:由于网络速度等原因导致的页面加载错误

相关问题 更多 >

    热门问题