I am trying to pars开发者_StackOverflow社区e the text between the script tag. I found examples to parse div, href but nothing for script tag. Any help would be great thanks.
<script type="text/javascript"
src="http://qw.com/?cmd=gn-pcode-ajax&cd=1145040425"></script>
short answer
//script/text()
should work.
considerations
You might reflect on the fact that there are not xpath expressions for div and others for scripts. Rather an XPath expression depends as much on the position of the node as on its node-name.
In the example you give there is no text entity between the opening and the closing script tag because you show the form where the script is referenced rather than in-line. So that I'm not too sure if you actually want
//script/@src
short explanation
The
//
means wherever the script tag might appear in the HTML tree.//script
means any descendant element of the document root of the context node, having a QName equal toscript
(local name equal to "script" and empty or null namespace URI).//script/text()
means any text appearing under these nodes.
There are any XPath tutorials on the net for you to delve deeper in that powerful expression language.
精彩评论