Python Selenium Instagram Bot

我现在正在构建Instagram机器人,我有一个问题。 我希望机器人继续像我的提要中的图片一样点击。 我做了这样的事情:

self.driver.find_element_by_css_selector('article._8Rm4L:nth-child(1) > div:nth-child(3) > section:nth-child(1) > span:nth-child(1) > button:nth-child(1)').click()
time.sleep(3)
self.driver.find_element_by_css_selector('article._8Rm4L:nth-child(2) > div:nth-child(3) > section:nth-child(1) > span:nth-child(1) > button:nth-child(1)').click()
time.sleep(3)

它一直这样,我有什么办法可以比写1,2,3,4 ...

tou999999 回答:Python Selenium Instagram Bot

您必须添加滚动条才能继续喜欢Feed中的图像

我的代码:

         SCROLL_PAUSE_TIME = 0.5
             # Get scroll height
              last_height = self.driver.execute_script("return 
              document.body.scrollHeight")
              while true:
             # Scroll down to bottom


            self.driver.execute_script("window.scrollTo
           (0,document.body.scrollHeight);")
# Wait to load page
sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = self.driver.execute_script("return document.body.scrollHeight")

last_height = new_height
,

使用Xpath更好=> find_element_by_xpath() 要么 您可以使用Selenium IDE来记录evey内容并保存为python文件进行编辑。

本文链接:https://www.f2er.com/3154577.html

大家都在问