ruby watir 获取页面的 html
我已经浏览了这些页面上的示例
http://watir.com/examples/ http://wiki.openqa.org/display/WTR/Examples
我还是不知道没有看到获取页面 html 的简单示例。
browser = Watir::Browser.new
browser.goto 'mysite.com'
我已经尝试过
puts browser.text
似乎不起作用。
谢谢
I have looked through the examples on these pages
http://watir.com/examples/
http://wiki.openqa.org/display/WTR/Examples
I still don't see a simple example of getting html of a page.
browser = Watir::Browser.new
browser.goto 'mysite.com'
I have tried
puts browser.text
It seems not working.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该可以做到:
This should do it:
将返回所有 html,如果您只想打印活动对象,您可以使用:
同样,如果您只想打印链接,您可以使用:
Will return all of the html, in case you only want to print the active objects, you can use:
Similarly if you only want the links to be printed, you can use:
IE8、Ruby 1.9.3、Watir 3.0、WindowsXP
我需要抓取 id="numberCovered" 的单元格中的文本。
正如 @icn 提到的,当您找不到合适的 Watir 内置方法时,有时可以使用原始页面源转储作为后备。
- 更新 -
上面提到的 $browser.html 正在喷出空行,但这似乎有效:
IE8, Ruby 1.9.3, Watir 3.0, WindowsXP
I need to grab the text in a cell with id="numberCovered".
As @icn mentioned, a raw page source dump is sometimes nice to have as a fallback when you can't find an appropriate Watir builtin method.
--Update--
The above mentioned $browser.html was spewing empty lines, but this seeems to be working:
puts browser.html
将返回页面上的所有对象。如果您只想要活动对象,那么您可以使用putsbrowser.show_active
,类似地,如果您只想显示链接,您可以使用putsbrowser.show_links
,它将显示所有页面上的链接。puts browser.html
will return all the objects on the page. If you want only the active objects then you can use putsbrowser.show_active
similarly if you want only the links to be displayed you can use putsbrowser.show_links
which will show all the links on the page.