0

My situation is the following: I am writing a bot to automate scrolling through instagrams explore page. I want to like the first 100 pictures that appear for a given hashtag.

I am using: Selenium, python, chrome.

My problem is the following: Whenever I scroll, new posts “appear” and old ones “disappear”. I am using an xpath like this: //article[row]. However, this only works for the first 10 rows since then row 11 is actually row 8 because previous pictures that I have already passed do no longer appear on the same level.

Does somehow know how to handle such a situation? I would like to access every single picture in a dynamically changing page where new pictures are added when I scroll down and older ones disappear.

Thank you so much!

Max
  • 33
  • 1
  • 3
  • Please share your code trials including the link to the page you working on. Otherwise this question is missing minimal debugging details – Prophet Jan 20 '23 at 07:15

2 Answers2

0

You gotta use a loop.

pseudocode:

posts = []
while something:
   posts.extend(driver.find_posts())
   driver.scroll_till_current_posts_disappeared

for scrolling, at https://stackoverflow.com/a/74508235/20443541

kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21
  • Yes, I understand this. My problem is not the scrolling aspect or the loop. My problem is how to control the scrolling and how to make sure I only select images that haven't been selected previously. I appreciate the pseudocode but it doesn't help me much. – Max Jan 20 '23 at 08:54
  • See below for the answer – Max Jan 20 '23 at 09:24
0

By chance I found an answer to this question: Find next sibling element in Selenium, Python?

Basically you have to use JS: next_sibling = driver.execute_script("""return arguments[0].nextElementSibling """, element)

Max
  • 33
  • 1
  • 3