我用WatiN迭代了一个非常大的div列表(大约3000个),我得到了错误:
A first chance exception of type 'System.OutOfMemoryException' occurred in WatiN.Core.dll
System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
at WatiN.Core.UtilityClasses.UtilityClass.TryFuncFailOver[T](DoFunc`1 func, Int32 numberOfRetries, Int32 sleepTime)
at WatiN.Core.Native.InternetExplorer.IEElement.GetWithFailOver[T](DoFunc`1 func)
at WatiN.Core.Native.InternetExplorer.IEElement.GetAttributeValue(String attributeName)
at WatiN.Core.Element.GetAttributeValueImpl(String attributeName)
at WatiN.Core.Component.GetAttributeValue(String attributeName)
at WatiN.Core.Element.get_OuterHtml()
at WatiN.Core.Document.get_Html()当单击一个div然后获取浏览器的html时。
有谁知道如何解决内存问题吗?我希望我可以使用不同的函数或以某种方式拆分页面。也许我需要使用WatiN之外的其他东西
代码是:
foreach (Div d in browser.Divs)
{
try
{
d.Click(); // click div
System.Threading.Thread.Sleep(250); //wait for new data to load
string url = "";
if (browser.Html.Contains("http://www.google.com/url?")) // check if an external link exists on the page - this causes the memory exception
{谢谢你的帮助
克里斯
发布于 2011-12-29 05:45:17
在这种情况下,这是Internet Explorer的一个问题,因为它使用的内存量超过了1 1GB,并且可能达到了某个地方的32位.net对象限制。
在我的例子中,在64位系统上运行“修复”(或者更确切地说,延迟)了这个问题。
发布于 2011-12-26 19:45:29
首先,当您等待页面时,不要使用用户线程睡眠,您可以使用browser.WaitForComplete()
如果你正在查看链接是否将你带到特定的页面,你可以像这样直接检查浏览器的url : browser.Url.Contains("address") ...
https://stackoverflow.com/questions/8632259
复制相似问题