how get the value of a script tag

不羁岁月 提交于 2019-12-11 16:34:32

问题


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>

How can I get the value of oid with watir or ruby?


回答1:


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

Then--as @rainkinz indicates--you can extract whatever values you want using regex:

b.script.html.match(/var\soid\s\=\s\"\d+\"/)


来源:https://stackoverflow.com/questions/15485345/how-get-the-value-of-a-script-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!