python - 无论如何我可以在不使用标记名的情况下获得 href 吗?
问题描述
def get_posts(driver):
posts = []
WebDriverWait(driver,10).until(EC.presence_of_element_located((By.TAG_NAME,"a")))
links_of_posts = driver.find_elements_by_tag_name('a') # gets all elements with tag a and puts them in a list
for links in links_of_posts:
post = Post()
if hasattr(links,'href'): #ERROR: no elements successfully enter the if, removing the if causes a stale element reference exception
post.link = links.get_attribute('href')
if '/p/' in post.link:
posts.append(post)
所有元素的 DOM 结构都应该是这样的,除了 href 不同:...
我使用的页面是 Instagram 个人资料页面,所以https://www.instagram.com/definitelynotbot24/
links_of_posts 包含应该有超链接的元素,但似乎没有一个元素这样做,有什么提示吗?
解决方案
推荐阅读
- php - 在 Laravel 和 Livewire 中抛出 errorException 时捕获
- python - Python 内存地址:Linux 上 Python 3.5 - 3.9 的变化
- linux - 在 shell 脚本中使用单引号 (') - RSYNC 问题
- sql - 我的左连接查询不包含指定表达式作为聚合函数的一部分
- async-await - F# 中的嵌套异步上下文
- algorithm - 如何使用Scala返回二叉树中节点的所有路径(分支)列表?
- xamarin - 将来自 web 服务调用的图像保存在本地 PCL 文件夹 Xamarin Forms 中
- laravel - 将 whereHas 中的值与父数据进行比较
- docker - 如何在基于 docker 的气流上安装 Kubernetes 操作员和执行程序
- sql-server - 当 SQL 中的组合没有数据时创建空行