机械化的局限性是什么? mechanize 和 watir 之间有什么区别
我正在使用 mechanize 来废弃一些网页。
- 我需要知道机械化的限制是什么?机械化不能做什么?
- 它可以执行嵌入网页中的JavaScript吗?
- 我可以用它来调用 javascript 函数吗?我认为不可以。我认为 Watir 可以。
- 它和watir有什么区别?
I am using mechanize to scrap some web pages.
- I need to know what are mechanize limitations? What mechanize can not do?
- Can it execute javascripts embedded in the web page?
- Can I use it to call javascript functions? I don't think it can. I think Watir can.
- What are the differences between it and watir?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
机械化可以做很多事情。它使用 net/http,所以无论你能用 net/http 做什么,你都可以用 mechanize 来做。尽管根据他们的描述它支持更多:
查看此链接,了解有关在 mechanize 中使用 javascript 的一些信息:这里
告诉您 mechanize 是否支持特定功能/任务而不是遍历所有内容会更容易。您到底想做什么?
Javascript 是 mechanize 做不到的一件事。它大多数时候支持的一件事是显示 Javascript 链接。即使用
page.links.each {|link| puts link.text}
也会显示 Javascript,但您将无法单击/选择它们。简单来说,Watir 确实支持 Javascript。实际上是您的浏览器支持 javascript,而 Watir 控制着浏览器。
Watir 运行一个真正的浏览器(FF、Chrome、IE)并以编程方式控制该浏览器。它的行为与用户访问网站时的行为完全相同。这就是您能够使用 javascript 的原因。 Watir 仅控制浏览器,浏览器是发送请求、获取响应并渲染/处理所有内容的浏览器。您受到所使用浏览器速度的限制。
另一方面,Mechanize 的行为就像它自己的“浏览器”,并且比 Watir 快得多,因为它不渲染页面。它直接与服务器对话,并处理原始响应。 Mechanicalize 受到连接速度的限制。
当您需要观察正在发生的事情、使用 javascript 或执行任何与 GUI 相关的操作时,可以使用 Watir,而不是 Mechanize。 Mechanize 速度更快,并且有利于测试网站的实际结构。 (测试链接/登录/等)
Mechanize can do a lot. It uses net/http so whatever you can do with net/http you can do with mechanize. Although it supports much more as per their description :
Check out this link for some information on using javascript with mechanize: here
It would be much easier to tell you if mechanize support a specific function/task instead of going through everything. What are you looking to do exactly ?
Javascript is the one thing mechanize can't do. The one thing it does support most of the time is displaying Javascript links. ie using
page.links.each {|link| puts link.text}
will also display Javascript, but you won't be able to click/select them.In simple terms Watir does support Javascript. It's actually your browser that supports javascript and Watir controls the browser.
Watir runs a real browser(FF,Chrome,IE) and programmatically controls that browser. It acts exactly like a user would when accessing a website. This is what enables you to use javascript. Watir only controls the browser and the browser is the one sending requests and getting responses and rendering/processing it all. You are limited by the speed of the browser you use.
Mechanize on the other hand acts like its own 'browser' and is much faster than Watir, becomes it does not render pages. It talks directly with the server, and processes the raw response. Mechanize is limited by your connection speed.
Watir would be used over Mechanize when you need to watch and see what's happening, use javascript, or do anything GUI related. Mechanize is much faster and is good for testing the actual structure of the website. (testing links/logins/etc)