Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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 使用查询获取不带div的所有body元素_Python_Html_Selenium - Fatal编程技术网

Python 使用查询获取不带div的所有body元素

Python 使用查询获取不带div的所有body元素,python,html,selenium,Python,Html,Selenium,我试图在查询中获取所有body元素,但不包含divs元素,这是我的代码 body = driver.find_element(By.TAG_NAME, 'body') elements = body.find_elements(By.TAG_NAME, '*') 但是通过这个,我得到了所有的元素,我想要的不是div元素的元素 是否可以通过一个查询完成此操作?尝试使用以下方法: elements = body.find_elements(By.XPATH, './/*[not(self::div

我试图在查询中获取所有body元素,但不包含divs元素,这是我的代码

body = driver.find_element(By.TAG_NAME, 'body')
elements = body.find_elements(By.TAG_NAME, '*')
但是通过这个,我得到了所有的元素,我想要的不是div元素的元素

是否可以通过一个查询完成此操作?

尝试使用以下方法:

elements = body.find_elements(By.XPATH, './/*[not(self::div)]')
尝试使用以下方法:

elements = body.find_elements(By.XPATH, './/*[not(self::div)]')
请尝试
*:not(div)
。在CSS选择器中工作,不确定,它在这里工作…尝试
*:not(div)
。在CSS选择器中工作,不确定,它将在这里工作…