简体   繁体   English

使用 python/selenium 定位 Instagram 中的赞滚动条

[英]Using python/selenium to target the likes scroll bar in instagram

I am trying to scroll through the scroll bar that appears when I click likes on my photos on instagram and get the profiles that liked each photo.我正在尝试滚动浏览当我在 Instagram 上点击喜欢的照片并获取喜欢每张照片的个人资料时出现的滚动条。 Unfortunately I am having trouble targeting the dialog box.不幸的是,我无法定位对话框。

Here is the html code:这是html代码:

<div class="pbNvD  fPMEg   " role="dialog">
    <div class="                   Igw0E     IwRSH      eGOV_  vwCYk"style="max-height: 356px; min-height: 200px;">
         <div style="height: 356px; overflow: hidden auto;">
         </div>
    </div>
<div>

Here is the code that I have tried so far but while there is no error, it does not scroll:这是我到目前为止尝试过的代码,但虽然没有错误,但它不会滚动:

fBody  = driver.find_element_by_xpath("//div[@class='pbNvD  fPMEg   ']")
scroll = 0
fList = []


n = 0
while n < 5: # scroll 5 times
    n = n +1
    driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', fBody)
    time.sleep(1)

If you always want to scroll to the end of the page,the easiest way to do is:如果您总是想滚动到页面末尾,最简单的方法是:

fBody.send_keys(Keys.END)

Another one if you want to scroll down to one page only:如果您只想向下滚动到一页,则使用另一个:

fBody.send_keys(Keys.PAGE_DOWN)

More details here: https://stackoverflow.com/a/27760083/6042903更多细节在这里: https : //stackoverflow.com/a/27760083/6042903

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM