如何获取脚本标签的值 [英] how get the value of a script tag
本文介绍了如何获取脚本标签的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的页面代码中,有这个脚本标签:
In my page code, there is this script tag:
<script>
var oid = "182384";
document.getElementById('container').innerHTML = oGrid;
oGrid.setShowSid(false);
oGrid.calcSize();
setupAllTabs();
var toolbar = setupMenuButtons("btnbar");
initForm(toolbar);
</script>
如何使用 watir 或 ruby 获取 oid 的值?
How can I get the value of oid with watir or ruby?
推荐答案
browser.script.html
将输出 标签内的代码.例如:
browser.script.html
will output the code within the <script>
tag. For example:
require 'watir'
browser = Watir::Browser.new
browser.goto("http://www.some_site_with_script.com")
browser.script.html
然后——正如@rainkinz 所指出的——你可以使用正则表达式提取任何你想要的值:
Then--as @rainkinz indicates--you can extract whatever values you want using regex:
b.script.html.match(/var\soid\s\=\s\"\d+\"/)
这篇关于如何获取脚本标签的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文