【发布时间】:2021-12-07 08:45:14
【问题描述】:
我的代码需要帮助。我在 python 中使用 Selenium
elems = driver.find_element_by_xpath("//article[@class='page-container']/section/div[3]")
for job in elems:
job_list.append(job.get_attribute('href'))
print(job_list)
The error is "TypeError: 'WebElement' object is not iterable".
我知道 elems 的结果是一个 WebElement,但我需要使用 find_element_by_xpath 因为我想要一个特定的 div 而这个 div 没有唯一的 id。我没有找到将 WebElement 转换为(例如)字符串的方法。 您是否知道另一种方法来拥有这个特定的 div 但不使用 find_element_by_xpath? 你有什么其他的想法来解决这个问题吗?
【问题讨论】:
-
xpath 只返回一个元素,似乎没有这样的元素,所以我猜它返回一个 web 元素
标签: python html selenium url typeerror