简体   繁体   English

如何使用Xpath解析Javascript?

[英]How can I parse Javascript using Xpath?

I am trying to parse the html pages using php xpath, there are some data that are inserted into html through javascript, for example 我正在尝试使用php xpath解析html页面,例如,通过javascript将一些数据插入到html中

<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. 我想单独提取数据“ hi SomeUserName”。

Is it possible to do this in php xpath? 是否有可能在php xpath中做到这一点? or is there a best way to do this? 还是有最好的方法做到这一点?

You can use jParser - A JavaScript parsing library for PHP for parsing JavaScript code inside <script> tag. 您可以使用jParser-一个用于PHP的JavaScript解析库来解析<script>标记内的JavaScript代码。 And to get <script> tag, DOMDocument or any other HTML parser can be used. 为了获得<script>标记,可以使用DOMDocument或任何其他HTML解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM