WatiN - 等待 Cookie
我被指派去创建一种“某种”网络爬虫。任务是访问某些网站,输入一条数据,然后提交该数据以接收结果。
我发现 WatiN 是获取这些数据的一个很好的工具,因为它是开源的,并且具有我需要的所有功能 - 即使这是对测试 API 的滥用(这是滥用吗?)。
无论如何 - 真正的问题是,
Browser.WaitForComplete();
不会等待所有内容加载。看起来它只是等待最后一个 body
标签然后返回。然而,我相信当页面加载完成时,cookie 不会生成,因为它是由 ASP.NET 后端生成的 - 它似乎是在看起来像 AJAX 或类似内容的交互式对象之后加载的。
我不拥有或托管该网站,因此只能根据我从浏览器和我可以使用的其他工具中看到的信息来收集信息。
有什么办法让WatiN等待cookie更新吗?
提前致谢。
约翰.
编辑:
作为我目前正在做的解决问题的示例(这有点不正统,但它正在立即解决)。
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
var cookie = Browser.Eval("document.cookie");
现在你可能明白为什么我想找到一个真正的解决方案了。
谢谢
I have been assigned to create a 'kind of' web creeper. The tasks is to go on certain websites, enter a piece of data then submit that data to receive a result.
I have found WatiN to be a great tool at getting this data as it's open source and has all the functionality I need - even if this is misuse of a Testing API (Is it misuse?).
Anyway - What the real question is, is that the
Browser.WaitForComplete();
Does not wait for EVERYTHING to load. It seems it just waits for the last body
tag then returns. However I believe the cookie is not generated when the page is finished loading as it's being generated by an ASP.NET back end - it seems to load after an interactive object which looks like AJAX or something along them lines.
I do not own or host the web site therefore can only gather information based on what I see from the browser and other tools at my disposal.
Is there any way to get WatiN to wait for the cookie to be updated?
Thanks in advanced.
John.
Edit:
As an example of what I'm doing to fix the issue at the minute (Which is a bit unorthodox but it's fixing it for the minute).
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
Browser.WaitForComplete();
var cookie = Browser.Eval("document.cookie");
Now you may understand why I want to find a real solution.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否可以捕获此事件,因为我怀疑页面上一定有 JavaScript 正在运行,最终会更新 cookie。
如果你能区分“旧”和“更新”cookie,你可以尝试这样的方法:
这不是一个很好的方法,但它应该在没有更好的方法的情况下工作。
I'm not sure could capture an event for this, as I suspect there must be javascript running on the page that ultimately updates the cookie.
If you can tell the difference between an "old" and "updated" cookie, you could try something like this:
This isn't a nice way of doing it, but it should work in the absence of anything better.