Python Selenium : Scrolling not working

标签 python selenium

我正在尝试自动化this Instagram 链接。我需要滚动并滚动并获取所有链接。我正在尝试关注但不起作用。

def fetch_links_by_hashtag(hash_tag):
    url = 'https://www.instagram.com/explore/tags/marketing/'
    driver.get(url)
    driver.implicitly_wait(20)
    is_more = False

    try:
        elem_more = wait.until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Load more")))
        elem_more.click()
        is_more = True
    except Exception as ex:
        print(str(ex))

    pop = driver.find_element_by_tag_name('footer')
    #pop = driver.find_element_by_link_text('About us')
    # pop = driver.find_element_by_class_name('_4gt3b')
    if pop is not None:
        for i in range(10):
            print('Calling scrolling script')
            # It scolls till end
            driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', pop)
            sleep(4)
        html = pop.get_attribute('innerHTML')
        print(html)

最佳答案

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

How to scroll down to the bottom of a page ?

关于Python Selenium : Scrolling not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41758095/

相关文章:

python - Bokeh ResetTool 预期行为

python - 等待一切完成(异步)

ruby - 如何在 capybara/ruby 环境下稳定 IE 窗口

php - Selenium:如何断言某个元素存在于某个表的某个单元格中?

selenium - 如何使用 Selenium WebDriver 打开新选项卡并启动链接?

python - PIL透视变换,计算出(a,b,c,d,e,f,g,h)

python - 在我的模型定义中创建一个数组列

python - 哪个异常捕获 python 中的 xxxx 错误

python 和 selenium webdriver 等待时间等于特定时间

javascript - 如何完整下载页面源代码,而不是部分下载?