首页 > 解决方案 > 用硒检查网页元素的颜色

问题描述

我正在使用 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)

它返回“无”

如果您有任何知识,请帮助

标签: pythonhtmlseleniumautomationinstagram

解决方案


推荐阅读