python - 硒。x 轮播中数据的路径
问题描述
我希望下面的脚本打印一堆车名
我想我没有正确指向旋转木马。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome(executable_path=r"../Downloads/chromedriver.exe")
driver.get('https://www.nationwidevehiclecontracts.co.uk/?msclkid=22db17e69fc512c5ab9f49993f841304&utm_source=bing&utm_medium=cpc&utm_campaign=B%20-%20NVC%20Brand%20-%20(Exact)&utm_term=nationwide%20car%20leasing&utm_content=Brand%20Variations')
carousel_x_path="/section[@class='section section--widget section--full-carousel section__heading-scroll variant-display']"
WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,carousel_x_path)));
for name in (driver.find_elements_by_xpath(carousel_x_path+"/span[@class='make']")):
print("it found a name")
print(name.get_attribute("textContent"))
我得到这个错误。
Traceback (most recent call last):
File "C:\Users\User\Desktop\miniiiiii.py", line 10, in <module>
WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,carousel_x_path)));
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
你能告诉我有什么问题吗
解决方案
请检查以下解决方案
driver = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
driver.get('https://www.nationwidevehiclecontracts.co.uk/?msclkid=22db17e69fc512c5ab9f49993f841304&utm_source=bing&utm_medium=cpc&utm_campaign=B%20-%20NVC%20Brand%20-%20(Exact)&utm_term=nationwide%20car%20leasing&utm_content=Brand%20Variations')
driver.maximize_window()
WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//body[@name='top']/section[@id='hotdeals']")))
links = driver.find_elements_by_xpath("//body[@name='top']/section[@id='hotdeals']/div[@id='offer-carousel']/div[@class='slick-list draggable']//h3//a")
for name in links:
print name.text
注意:请在您的解决方案中添加以下导入
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
推荐阅读
- python - 如何获取每个键索引(第一级)的值并使用它来做某事
- assembly - NASM 汇编器浮点加法
- sqlite - Sqlite pviot 添加带有总计的计数行
- python - 在 python 中创建脚本以更改 SVG 文件中的文本
- javascript - 将输入字段中的数组显示为数组
- python - sklearn.datasets.make_s_curve 输出含义
- django - 获取按最近条目排序的主题
- android - 为 cordova/phonegap 过滤 Android Studio Logcat
- sql-server - 使用 .GroupBy() 方法将此 SQL 查询转换为 LINQ
- forms - Symfony 4 - 默认值形式不起作用