Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.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 你有下一个兄弟姐妹吗_Python_Python 2.7_Selenium - Fatal编程技术网

Python 你有下一个兄弟姐妹吗

Python 你有下一个兄弟姐妹吗,python,python-2.7,selenium,Python,Python 2.7,Selenium,我或多或少有这种结构,如何选择title之后的下一个元素?起始点必须是x或y,因为结构具有重复的类等等,而这一点是唯一的锚定点。只是为了澄清,我需要抓住的内容和参考是标题 x=wd.find\u elements\u by\u class\u name('title')[0]//打印标题0 y=wd.find_elements_by_class_name('title')[1]//打印标题1 HTML: 标题0 Content0 标题1 Content1 如果您正在使用selenium,请尝

我或多或少有这种结构,如何选择
title
之后的下一个元素?起始点必须是
x
y
,因为结构具有重复的类等等,而这一点是唯一的锚定点。只是为了澄清,我需要抓住的内容和参考是标题

x=wd.find\u elements\u by\u class\u name('title')[0]//打印标题0
y=wd.find_elements_by_class_name('title')[1]//打印标题1
HTML:


标题0

Content0

标题1

Content1


如果您正在使用selenium,请尝试按照
css
选择器获取基于类标题的p标记

驱动程序。通过css选择器(“title+p”)查找元素

以获取内容值

for item in driver.find_elements_by_css_selector(".title+p"):
    print(item.text)

如果您正在使用selenium,请尝试按照
css
选择器获取基于类标题的p标记

驱动程序。通过css选择器(“title+p”)查找元素

以获取内容值

for item in driver.find_elements_by_css_selector(".title+p"):
    print(item.text)

对于特定元素:

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[1]'  #Content0

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[2]'  #Content1
for content in driver.find_elements(By.XPATH, '//p[@class()="title"]/following-sibling::p'):
    print(content.text)
对于所有元素:

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[1]'  #Content0

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[2]'  #Content1
for content in driver.find_elements(By.XPATH, '//p[@class()="title"]/following-sibling::p'):
    print(content.text)

对于特定元素:

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[1]'  #Content0

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[2]'  #Content1
for content in driver.find_elements(By.XPATH, '//p[@class()="title"]/following-sibling::p'):
    print(content.text)
对于所有元素:

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[1]'  #Content0

driver.find_element(By.XPATH, '(//p[@class()="title"]/following-sibling::p)[2]'  #Content1
for content in driver.find_elements(By.XPATH, '//p[@class()="title"]/following-sibling::p'):
    print(content.text)

这回答了你的问题吗,这回答了你的问题吗,