I'm building now Instagram bot and I have a question. I want the bot to keep hitting like on the pictures in my feed. I did something like this:
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)
And it keeps going like this, there is any way I can do it easier than write 1,2,3,4...
You must add scrolling to it in order to continue liking images in the feed
My code:
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
Use Xpath it is better => find_element_by_xpath() Or You can use selenium IDE to record evey thing and save it python file to edit it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.