Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.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 id_Python_Selenium - Fatal编程技术网

Python 如何循环检索div id

Python 如何循环检索div id,python,selenium,Python,Selenium,我尝试使用selenium从网站检索帖子-标题、url和图像。我已经到了第一级,但在第二级,post从(div id=“abcde-11-0”)开始到(div id=“abcde-11-20”),在这种情况下,在到达(a herf)检索数据之前,我应该如何进入第二级 这是我的代码: # I get to the first level by using xpath Container=chromedrv.find_elements_by_xpath("//*[@id="Mai

我尝试使用selenium从网站检索帖子-标题、url和图像。我已经到了第一级,但在第二级,post从(div id=“abcde-11-0”)开始到(div id=“abcde-11-20”),在这种情况下,在到达(a herf)检索数据之前,我应该如何进入第二级

这是我的代码:

# I get to the first level by using xpath
Container=chromedrv.find_elements_by_xpath("//*[@id="MainContent"]/div[2]/div/div/div[6]/div[2]")

我想知道我是否正确理解了你的问题,但请使用此代码

first_level_rows =chromedrv.find_elements_by_xpath('//*[@id="MainContent"]/div[2]/div/div/div[6]/div[2]')

for first_level_row in first_level_rows:
    second_level_rows = first_level_row.find_elements_by_xpath('//*[contains(@id, "abcde-11-")]')

查找元素通过xpath('/*[contains(@id,“abcde-11-”)=>此部分提取id中包含“abcde-11-”的所有标记。

使用相关HTML更新问题。谢谢Ahmed,但出现了错误-没有这样的元素:无法找到元素:{“方法”:“xpath”,“选择器”:“/*[contains(@id,'HomePageInternational-riverPlus-”)]]”}您好,你在哪里看到“HomePageInternationalRiverPlus-”?我在你的帖子里没看到。