问题描述
我想自动滚动并截取的屏幕截图。页面本身不可滚动,因此 $ 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).
推荐答案
似乎< 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).
=
- 在分配和比较之间没有区别(根据):
There is no differentiation for =
-use between assignment and comparison (as per Documentation - Language Reference - Operators):
这篇关于滚动网页上的元素以截取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!