Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python/Selenium:识别所有Instagram心脏和';比如';他们_Python_Selenium_Instagram - Fatal编程技术网

Python/Selenium:识别所有Instagram心脏和';比如';他们

Python/Selenium:识别所有Instagram心脏和';比如';他们,python,selenium,instagram,Python,Selenium,Instagram,该程序应该检测Instagram中的所有心脏,然后给出一个“Like”。我知道有一个Instagram API,但正在尝试使用Selenium实现教育应用程序。此外,我使用的是Chrome 这就是我迄今为止所尝试的: # scroll down to the bottom of the page driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") driver.maximize_window() #

该程序应该检测Instagram中的所有心脏,然后给出一个“Like”。我知道有一个Instagram API,但正在尝试使用Selenium实现教育应用程序。此外,我使用的是Chrome

这就是我迄今为止所尝试的:

# scroll down to the bottom of the page
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

driver.maximize_window()

# find all heart links
hearts = driver.find_elements_by_xpath("//button[@class='dCJp8 afkep coreSpriteHeartOpen _0mzm-']")

for i in range(len(hearts)):
    hearts[i].click()
    sleep(3)
错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: Element <button class="dCJp8 afkep coreSpriteHeartOpen _0mzm-">...</button> is not clickable at point (192, 20). Other element would receive the click: <div class="                  Igw0E   rBNOH        eGOV_     ybXk5    _4EzTm                                                                                                              ">...</div>
  (Session info: chrome=71.0.3578.98)

我不太确定。我猜您尝试单击的元素不在屏幕上。尝试先滚动到元素,然后单击

我不太确定。我猜您尝试单击的元素不在屏幕上。尝试先滚动到元素,然后单击

这应该有效:

likeButtonPath='section.ltpMr.Slqrh>span.fr66n>button>div>span>svg[aria label=“Like”]
elements=LOGINPG.find_elements_by_css_selector(如按钮路径)
对于元素中的元素:
LOGINPG.execute_脚本('参数[0]。scrollIntoView({行为:“平滑”,块:“中心”,内联:“最近的”}'),元素)
元素。单击()

likeButtonPath='section.ltpMr.Slqrh>span.fr66n>button>div>span>svg[aria label=“Like”]
elements=LOGINPG.find_elements_by_css_selector(如按钮路径)
对于元素中的元素:
LOGINPG.execute_脚本('参数[0]。scrollIntoView({行为:“平滑”,块:“中心”,内联:“最近的”}'),元素)

element.click()
我尝试在.click()之前添加一个find_元素标记,但没有成功。这不是我的意思,你可以尝试使用actionchain移动到元素,或者只执行JavaScript将元素放入视图中。我需要深入研究actionchain,但不熟悉它。在阅读actionchain文档之后,我设法解决了这个问题。您的评论为我提供了指导,但没有提供正式的答案,因此我已对其进行了浏览。我尝试在.click()之前添加一个find_元素标记,但没有效果。这不是我的意思,您可以尝试使用actionchain移动到元素,或者只执行JavaScript将元素放入视图中。我需要深入研究actionchain,不熟悉。在阅读了Actionchain文档之后,我设法解决了这个问题。你的评论为我提供了指导,但没有提供正式的答复,因此,我用大拇指点击了它。你能解释一下Instagram js是如何检测到你点击的喜欢按钮的,因为在一个页面中有多个相同类名的喜欢按钮吗?你能解释一下Instagram js是如何检测到你点击的喜欢按钮的,因为在一个页面中有多个相同类名的喜欢按钮吗?
hearts = driver.find_elements_by_xpath("//span[@class='fr66n']")

for h in range(len(hearts)):
    ActionChains(driver).move_to_element(hearts[h]).click(hearts[h]).perform()
    print(hearts[h])