【发布时间】:2016-10-11 21:59:29
【问题描述】:
我正在编写一个带有加载网站的 WebView 的小型 MacOS 程序。这是当您滚动到底部时自动加载更多内容的网站之一。作为过期,我正在尝试编写将不断滚动到页面底部的代码,以便加载更多内容等等。
到目前为止,我所拥有的是:
scrollToBottomTotalTimes = 10
self.myWebView.mainFrame.load(NSURLRequest(url: NSURL(string: urlString)! as URL) as URLRequest!)
func webView(_ sender: WebView!, didFinishLoadFor frame: WebFrame!) {
var scrollToBottomCurrentTimes = 0
while scrollToBottomCurrentTimes != scrollToBottomTotalTimes {
scrollToBottomCurrentTimes += 1
self.myWebView.scrollToEndOfDocument(self)
sleep(2) //give the page some time to load
}
}
这一次效果很好:页面加载,滚动到底部,然后加载更多页面。
但是在那之后,WebView 不再滚动,尽管页面有足够的时间重新加载。页面上的位置与以前完全相同。
我感觉.scrollToEndOfDocument(self)似乎没有发现网页变长的事实。
有没有办法“更新”.scrollToEndOfDocument(self),让它知道页面的新底部在哪里?
谢谢!
【问题讨论】: