0

I am trying to parse 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>

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm pretty sure he needs only //script/@src +1 !
You wrote: "//script means any node, wherever it appears in the hierarchy, in which the local node name is script". That's misleading. In XPath 1.0 //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)
Thats right. Looks like I always take the null namespace for granted... ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.