滚动网页上的元素以截取屏幕截图 [英] Scrolling an element on a web page to take screenshots

查看:503
本文介绍了滚动网页上的元素以截取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动滚动并截取移动网站的屏幕截图。页面本身不可滚动,因此 $ oIE.document.parentwindow.scroll 不起作用。我不知道如何滚动该页面上的元素(其中包含我想要截取屏幕截图的内容)。

I want to automate scrolling and taking screenshots of a mobile site. The page itself is not scrollable, so $oIE.document.parentwindow.scroll doesn't work. I don't know how to scroll an element on that page (which contains the content I want to take screenshots of).

$oIE = _IECreate($page_likers_url)
While Not (IsObj($oIE))
    Sleep(1000)
    $oIE = _IECreate($page_likers_url)
WEnd
While $oIE.ReadyState <> 4
    Sleep(1000)
WEnd

$LastHeight = $oIE.document.body.scrollHeight
$Flag = True
$Times = 0

While $Flag And $Times < $MaxScrollTimes
    $oIE.document.parentwindow.scroll(0, $oIE.document.body.scrollHeight)
    Sleep(1000)
    If $oIE.document.body.scrollHeight == $LastHeight Then
        For $i = 0 To 29
            $oIE.document.parentwindow.scroll(0, $oIE.document.body.scrollHeight)
            Sleep(1000)
        Next
        $Times += 10
        If $oIE.document.body.scrollHeight == $LastHeight Then $Flag = False
    EndIf
    $LastHeight = $oIE.document.body.scrollHeight
    $Times += 1
WEnd

这是我通常使用的,但它不适用于可滚动元素(页面本身除外)。

This is what I normally use, but it does not work on scrollable elements (other than the page itself).

推荐答案


&hellip ;我不知道如何让它滚动页面的中间部分。

… I don't know how to let it scroll the middle section of the page.

似乎< div> -element可通过JavaScript代码滚动。可能是通过定位包含< li> -elements;例如:

Seems a <div> -element scroll-able by JavaScript code. Possibly by targeting contained <li> -elements; example:

#include <IE.au3>

Global Const $g_iDelay    = 1000 * 2
Global Const $g_sURL      = 'm.benlai.com'
Global Const $g_sIdFrame  = 'slider'
Global Const $g_sNameItem = 'li'

Global       $oIE         = _IECreate($g_sURL)
Global       $oFrame      = _IEGetObjById($oIE, $g_sIdFrame)
Global       $oItems      = _IETagNameGetCollection($oFrame, $g_sNameItem)

For $oItem In $oItems

    _IEAction($oItem, 'scrollintoview')
    Sleep($g_iDelay)

Next

_IEQuit($oIE)

$ oItem.scrollIntoView 。可能需要重复(如果在滚动时加载了额外的元素)。

Or $oItem.scrollIntoView. May require repetition (if extra elements load on scrolling).


这是我通常使用的代码…

This is the code I normally use …

= - 在分配和比较之间没有区别(根据文档 - 语言参考 - 运营商):

There is no differentiation for = -use between assignment and comparison (as per Documentation - Language Reference - Operators):


==

测试两个字符串是否相等。 区分大小写。如果左侧和右侧值不是字符串,则将其转换为字符串。只有在字符串比较需要区分大小写时才应使用此运算符。

==

Tests if two strings are equal. Case sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used if string comparisons need to be case sensitive.

这篇关于滚动网页上的元素以截取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆