繁体   English   中英

元素点击 Selenium 找不到要点击的按钮

[英]Element Click Selenium Not Finding Button to Click

对于下面的 url,我尝试单击“1-50”按钮(它有自己的 xpath),然后单击“51-100”、“101-150”等按钮(它们共享第二个 xpath) ,但我的代码似乎无法点击按钮。 有人能弄清楚吗? 干杯!

import pandas as pd
import time
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()

url = 'www.sec.gov/securities/files/year/'

page = driver.get(url)
time.sleep(2)

df_appended = []

df = pd.read_html(driver.page_source)[0]
df_appended.append(df)
    
time.sleep(2)
driver.find_element_by_xpath('//[@id="ctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592_updatePanelctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592"]/table[2]/tbody/tr/td/a/img').click
time.sleep(2)

for i in range(1,3):
    df = pd.read_html(driver.page_source)[0]
    df_appended.append(df)
    driver.find_element_by_xpath('//*[@id="ctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592_updatePanelctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592"]/table[2]/tbody/tr/td/a[3]/img').click()
    time.sleep(1)
    
df_appended

如果您使用 a 标签,则运行良好。

driver.find_element_by_xpath('//table[2]/tbody/tr/td/a').click()
time.sleep(2)

for i in range(1,3):
    df = pd.read_html(driver.page_source)[0]
    df_appended.append(df)
    driver.find_element_by_xpath('//table[2]/tbody/tr/td/a[3]').click()
    time.sleep(1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM