Heim >Backend-Entwicklung >PHP-Tutorial >javascript - php用xpath取页面中script里声明的变量值?

javascript - php用xpath取页面中script里声明的变量值?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:19:102235Durchsuche

php 用 xpath 取页面中 script 里声明的变量值?

<code><script>
var message = 'this is the text to be catch...';
</script></code>

比如某个网页里有上面一段内容,我想取其中的 message 的值取出来,可有办法?

我现在是整段拿到 html 再取 message 的,很不划算……

回复内容:

php 用 xpath 取页面中 script 里声明的变量值?

<code><script>
var message = 'this is the text to be catch...';
</script></code>

比如某个网页里有上面一段内容,我想取其中的 message 的值取出来,可有办法?

我现在是整段拿到 html 再取 message 的,很不划算……

难道你还能仅仅加载一个页面的一部分,这不现实啊,任何时候都是需要先完整获取页面,然后如果你不想完全采用正则来获取,你可以考虑使用类似jquery的php库
https://github.com/tburry/pquery

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn