【发布时间】: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