无法定位元素 href </a>

Unable to locate element href </a>

请找到附件图片,我想获取管理员和版主的姓名和 href link。

我试过以下:

grp="https://m.facebook.com/groups/162265541050378?view=members&ref=m_notif&notif_t=group_r2j_approved"
driver.get(grp)
root1=driver.find_element_by_id("//*[@id='rootcontainer']")
if root1>0:
    admin=driver.find_elements_by_xpath("//*[@class='_4kk6 _5b6s']")
    ilink = admin.get_attribute('href')
    ilink2=admin.get_attribute('<a>')
    print(ilink)

错误

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="//*[@id='rootcontainer']"]"}
  (Session info: chrome=91.0.4472.101)

对于管理员和版主姓名,您可以这样做:

for names in driver.find_elements(By.XPATH, "//div[contains(@id, 'member_')]/div[2]/descendant::h3[1]")
    print(names.text)

对于 href :

for hrefs in driver.find_elements(By.XPATH, "//div[contains(@id, 'member_')]/div[4]/descendant::a")
     print(hrefs.get_attribute('href'))

首先//*[@id='rootcontainer']是XPath,不是ID。所以你可以这样使用它

root1=driver.find_element_by_xpath("//*[@id='rootcontainer']")

或者这个:

root1=driver.find_element_by_id("rootcontainer")

另外这个ilink2=admin.get_attribute('<a>')也不正确。不会用。