0

I am trying to parse the html pages using php xpath, there are some data that are inserted into html through javascript, for example

<script type="text/javascript">     
   var insertName = function() {                
       var firstName = 'Hi SomeUserName';
       $('#welcomeMessage').html(firstName)
   }
</script>
<h1 id="welcomeMessage"></h1>

I want to extract the data 'hi SomeUserName' alone.

Is it possible to do this in php xpath? or is there a best way to do this?

1 Answer 1

1

You can use jParser - A JavaScript parsing library for PHP for parsing JavaScript code inside <script> tag. And to get <script> tag, DOMDocument or any other HTML parser can be used.

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

1 Comment

thanks for the information!, i just tried jparser, its first converting javascript to xml and i have to parse the xml again, though it gives a way to parse javascript its making the job more cumbersome in think, i am now using the normal string functions of php to get the required text.

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.