【问题标题】:Scroll down the posts Instagram home page selenium and python向下滚动帖子 Instagram 主页 selenium 和 python
【发布时间】:2020-07-10 03:11:29
【问题描述】:

我尝试向下滚动并喜欢 Instagram 主页上的帖子,而当我尝试去下一个帖子时,它又会上升。我正在尝试使用下一篇文章的类名

这是我的代码

    # Wait 3 second while the post-login page loads
    time.sleep(3)
    bot.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
        .click()
    time.sleep(3)
    bot.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
        .click()
    time.sleep(3)
     #Like the post
    followButton = bot.find_element_by_class_name('fr66n')
    followButton.click()
    time.sleep(5)

    #Go to the comment field
    nex = bot.find_element_by_class_name('sH9wk')
    time.sleep(1)
    nex.click()
    time.sleep(2)
     #Go to next post ...but here it's again going to the first post
    nex_post = bot.find_element_by_class_name('_9AhH0')
    time.sleep(1)
    nex_post.click()


   

【问题讨论】:

  • 我认为你没有滚动,所以元素没有出现在 DOM 中,因为 instagram 的页面是动态的。您必须使用 execute_script("window.scrollTo(0, vertical_pos);") 滚动,然后按类名查找帖子

标签: python selenium scroll instagram


【解决方案1】:

要向下滚动页面,只需输入这行代码

bot.execute_script('window.scrollTo(0,700)')

你可以键入向下滚动的大小而不是 700

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    相关资源
    最近更新 更多