0
votes

I tried to scrolling down with selenium, But i use webdriver PhantomJS. I tried selenium for test javascript instagram. As you know, on instagram there have button "Load More", after click button "Load More", we don't have to click again becouse it will auto refresh and it will show more image.

I tried like this :

driver.find_element_by_xpath("//a[@class='_8ioip _glw1t']").click()
time.sleep(5)

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3.6)

Actually this code it's work, but not really work, i mean something weird happening at the "time.sleep". If i give 2, the result are few and if i give 3 the result are just pretty much, But if i give 5, the result same like i give 2.

The question is, How to make teh Scroll get all data

1

1 Answers

1
votes

class of "Load more" button seems to have changed. your code is correct, try with this xpath:

//a[@class='_8imhp _glz1g']

or try to locate the button by it's text content:

//*/div/a[text()[contains(.,'Load more')]]

and before click the button scroll down.. so your code should looks like:

driver.get('https://www.instagram.com/explore/tags/whatever/')
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_xpath("//*[text()[contains(.,'Load more')]]").click()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")