Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Selenium-返回xpath中的所有文本_Python 3.x_Selenium_Xpath - Fatal编程技术网

Python 3.x Selenium-返回xpath中的所有文本

Python 3.x Selenium-返回xpath中的所有文本,python-3.x,selenium,xpath,Python 3.x,Selenium,Xpath,下面的代码应该返回给定xpath中的所有文本。此xpath对应于通道NPO 1的第一行EPG数据,但是我没有收到任何反馈: import sys import os import os.path from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.proxy import Proxy, ProxyType sys.p

下面的代码应该返回给定xpath中的所有文本。此xpath对应于通道NPO 1的第一行EPG数据,但是我没有收到任何反馈:

import sys
import os
import os.path
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.proxy import Proxy, ProxyType

sys.path.append("G:\\Python36\\mypath")

chrome_options = Options()  
chrome_options.add_argument("--headless")

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://tvepg.eu/en/netherlands/epg/main")

link_path = '/html/body/table/tbody/tr[215]/td[2]'

link_path2 = driver.find_elements_by_xpath(link_path)

for link in link_path2:
   
    print link.text
    
driver.quit()    
…关于我需要改变什么有什么想法吗


谢谢

我不确定你是否想要这个

导入
WebDriverWait
(),等待所有元素的
可见性
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://tvepg.eu/en/netherlands/epg/main")
elements=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.XPATH,"//table[@class='grid-container main-table']/tbody//tr[1]/td[1]//img[@class='card-img-topa']")))
for element in elements:
    print(element.get_attribute("alt"))
输出

NPO 1
NPO 2
NPO 1 extra
NPO 2 extra
RTL 4
RTL 5
SBS6
RTL 7
Net5
RTL 8
SBS9
RTL Lounge

够近了。我必须对它进行实质性的修改,以使它完全符合我的要求,但我的问题是没有正确定义XPath,这是您帮助我解决的,因此应该接受您的答案。谢谢