python - 用硒检查网页元素的颜色
问题描述
我正在使用 Python + Selenium 构建一个 Instagram 机器人,并且我正在尝试获取元素的填充属性(like 按钮)并让机器人喜欢它,如果 like_color != "#262626"
此代码的目标是避免不喜欢已经喜欢的帖子。
x7 = '//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button/div'
like_color = driver.find_element_by_xpath(x7).get_attribute("fill")
# #262626 means that the color is grey (not liked)
if like_color == '#262626':
# like_post() is the function that gives likes
like_post()
else:
print('Post already liked')
我尝试了这种方式和许多其他方式,但仍然没有结果..当我要求代码时
print(like_color)
它返回“无”
如果您有任何知识,请帮助
解决方案
推荐阅读
- c++ - 数据包访问实践
- go - 由于找不到本地包,无法将 Go 应用程序部署到 GAE
- wordpress - 从 WP Bakery Single Image Block 上传突然失败
- c - Ecore_Job 内存泄漏的可能性?
- javascript - 使用正则表达式提取计量单位
- c# - 使用 IIS 运行一个简单的 ASP.NET Core 应用程序,给出一个空白页
- android - 圆形图像视图未显示
- django - 如何从 python manage.py test 调用 pytest-django?
- javascript - Javascript过滤嵌套数组对象
- reactjs - 无法从提供者获取数据以在反应上下文中使用