scriptwindow__INITIAL_STATE__=json数据scriptPHP如何匹配网页中以上内容中的json数据?
PHP可以使用正则表达式来匹配网页中的JSON数据。以下是一个示例代码:
<?php
// 获取网页内容
$html = file_get_contents('http://example.com');
// 定义正则表达式
$pattern = '/<script>window.__INITIAL_STATE__=(.*?)<\/script>/s';
// 执行正则表达式匹配
preg_match($pattern, $html, $matches);
// 获取JSON数据
$jsonData = $matches[1];
// 解析JSON数据
$data = json_decode($jsonData, true);
// 输出JSON数据
var_dump($data);
?>
请注意,这只是一个示例代码,实际使用时需要根据具体的网页结构进行调整。
原文地址: https://www.cveoy.top/t/topic/i5cR 著作权归作者所有。请勿转载和采集!