python - 尝试在 webelement 中选择元素,但我得到 object is not callable 错误
问题描述
我一直在尝试选择 web 元素内的元素,我得到:“TypeError:'WebElement' 对象不可调用”
def get_engagmet(driver, time, a):
engagment = {}
body_element = driver.find_elements_by_xpath("//div[@class='_5pcr userContentWrapper']")
link = body_element[a].find_element_by_xpath(".//a[@rel='theater']")
print("this is link")
print(link("href"))
time.sleep(3)
无论如何,这应该有效。
解决方案
代替
print(link("href"))
和
print(link.get_attribute("href"))
PS 此外,您可能会分享您尝试抓取的 URL,以检查您的 XPath 是否正确匹配。
推荐阅读
- webusb - 'transferIn()'函数的执行速度是0.16s左右吗?
- python - 使用 numpy.save(和 savez)的意外类型错误
- python-3.x - 如何使用python对sqlalchemy中的简单垂直分区执行查询
- css - 从包含组件的角度应用 css
- javascript - 使用 jasmine 监视全局对象
- mysql - 为什么按sql排序要花这么多时间
- javascript - javascript:整数的紧凑序列化 (JSON)
- java - 合并两个 jacococ.exec 文件
- java - 图像上传到 onedrive “错误解释 JPEG 图像文件”
- javascript - JavaScript 使用 IE9 不支持的拼接从数组中查找和删除元素