driver.find_elements by tagname of "a" 显示空白结果

问题描述 投票:0回答:1

所以我得到了一个 python selenium 版本 4.15.2 脚本,我在其中打开此网页 https://app.logrocket.com/

我只想简单地获取页面中可用的所有超链接并将其存储在集合中 但它显示页面中没有可用的超链接,即使有

下面是代码

driver.get("https://app.logrocket.com/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.TAG_NAME, 'a'))) abc = driver.find_elements(By.TAG_NAME,'a') 

变量“abc”只显示空白 任何建议都会对我有帮助

我尝试了下面的代码

driver.get("https://app.logrocket.com/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.TAG_NAME, 'a'))) abc = driver.find_elements(By.TAG_NAME,'a') 

期望所有通常以标记名“a”开头的超链接应存储在“abc”变量中

python selenium-webdriver hyperlink ui-automation
1个回答
0
投票

您的代码应该可以工作 - 请记住,您提供的网站需要登录,到目前为止您只能抓取两个

<a>

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()
driver.get('https://app.logrocket.com/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.TAG_NAME, 'a'))) 
  
for e in driver.find_elements(By.TAG_NAME,'a'):
    print(e.get_attribute('outerHTML'))

输出:

<a href="javascript:void(0)">Sign Up</a>
<a class="auth0-lock-alternative-link" href="javascript:void(0)">Don't remember your password?</a>
© www.soinside.com 2019 - 2024. All rights reserved.