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

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

WBOY
Release: 2016-06-06 20:19:10
Original
2206 people have browsed it

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

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

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

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

回复内容:

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

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

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

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template