将当前网页保存在 Watin 中
我正在尝试使用 使用 Watin 显示 IE“另存为”对话框
所以这里是:
IE ie = new IE("http:// /本地主机"); // 更多代码
//我期望 out.html 是输出文件 FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("out.html");
//我希望这一行会弹出另存为对话框,但什么也没有发生 即.AddDialogHandler(fileDownloadHandler);
//程序被阻塞在这一行,因为它无法点击任何地方 ie.Link("startDownloadLinkId").Click();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
我也尝试了下面的代码,但它没有保存所有页面: System.IO.StreamWriter 文件 = new System.IO.StreamWriter("output.html"); file.Write(ie.Html);
同样,我需要从 Watin 保存网页,结果与手动保存相同。
谢谢!
I'm trying to save the full content of the current static web page, using the code from Show IE "Save As" dialog using Watin
So here it is:
IE ie = new IE("http://localhost");
// more code
//I expect out.html is the output file
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("out.html");
//I expect this line to popup the save as dialog box, but nothing happens
ie.AddDialogHandler(fileDownloadHandler);
//the program is blocked at this line, as it can't click anywhere
ie.Link("startDownloadLinkId").Click();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
I also tried the code below, but it doesn't save all the page:
System.IO.StreamWriter file = new System.IO.StreamWriter("output.html");
file.Write(ie.Html);
Again, I need to save the webpage from Watin, and the result to be the same as saving it manually.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我是这样做的:
当然,假设 myIE 是一个 WatiN IE 元素。
如果您在寻找如何使用 WatiN 执行某些操作时遇到困难,我经常发现在 google 上搜索如何使用“Internet Explorer COM 对象”执行此操作会很有帮助。 WatiN 包装了该对象,但它是公开的并且能够被访问!
干杯!
Here is how I do it:
Assumes myIE is a WatiN IE element, of course.
If you're ever having difficulty finding how to do something with WatiN, I often find it helpful to google how to do it with an "Internet Explorer COM object". WatiN wraps the object, but it is exposed and able to be accessed!
Cheers!
尝试使用 html agility pack 解析 html 并保存它,您可以使用其他功能...
链接到 agility pack
Try to parse the html with html agility pack and save it, there are additional abilities that you can use...
Link to agility pack