我想从以下java脚本部分获取extrat节点值.java脚本部分包含java脚本。我想用PHP html dom或regex。
<script>
*****************************************
**********************************
document.loginform.action ="../Login1.action";
document.loginform.submit();
}
</script>
我想在document.loginform.action =“我想得到这个文本”之间得到文本;两个引号。 请帮帮我。
答案 0 :(得分:1)
你可以试试这个:
从HTML中获取<script>
节点,如下所示:
x=document.getElementsByTagName("script");
str = x[0].innerHTML;
这将为您提供<scrip> and </script>
个节点之间的整个脚本内容。
拆分str
'
var arr = str.split(":");
这将为您提供包含所有行的数组。现在将数组中的所有document.loginform
字符串分组并继续进行。您需要检查包含“操作”的字符串。这将有助于您获得更准确的结果。
希望这会对你有所帮助。
答案 1 :(得分:1)
要完全按照您的要求进行操作,您可以使用正则表达式和每个脚本元素的text属性,但我认为您不会觉得它非常强大或实用。
window.onload = function() {
var script, scripts = document.scripts;
var re = /document\.loginform\.action =/;
var text;
for (var i=0, iLen=scripts.length; i<iLen; i++) {
script = scripts[i];
if (re.test(script.text)) {
text = script.text.match(/document\.loginform\.action ="[^"]+/)[0];
alert(text.split('"')[1]);
}
}
}
答案 2 :(得分:-1)
你甚至不是在搜索或者使用人们建议你的东西,这是一个寻求帮助的坏方法。 这是使用正则表达式的解决方案。
<?php
$html = <<<EOD
....
<script>
*****************************************
**********************************
document.loginform.action ="../Login1.action";
document.loginform.submit();
}
</script>
.....
EOD;
$match = preg_match('/document\.loginform\.action\s*=\s*"([^"]+)";/isU', $html, $result);
echo $match[1];
?>
您可能希望使用DOM Parser实现相同目的,您需要在此处查看:http://docs.php.net/manual/en/domdocument.loadhtml.php以获取更多信息。