开发者

php parse with xpath

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

  1. 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.

  2. 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

  1. The // means wherever the script tag might appear in the HTML tree.

  2. //script means any descendant element of the document root of the context node, having a QName equal to script (local name equal to "script" and empty or null namespace URI).

  3. //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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜