Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

python - Selenium Scroll inside of popup div

I am using selenium and trying to scroll inside the popup div on instagram.

I get to a page like 'https://www.instagram.com/kimkardashian/', click followers, and then I can't get the followers list to scroll down.

I tried using hover, click_and_hold, and a few other tricks to select the div but none of them worked.

What would the best way be to get this selected?

This is what I tried so far:

driver.find_elements_by_xpath("//*[contains(text(), 'followers')]")[0].click()
element_to_hover_over = driver.find_elements_by_xpath("//*[contains(text(), 'Follow')]")[12]
hover = ActionChains(webdriver).move_to_element(element_to_hover_over)
hover.click_and_hold()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The exact code is as follow. You first have to find the new iframe which contains the name of followers:

scr1 = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/div[2]')
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", scr1)

This will automatically scroll down the page but you have make a for loop for it until it reaches to the end of page. You can see my Instagram crawler here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...