<?php
$url = 'https://www.cbex.com.cn/xm/cqzr/201901/t20190107_26742.html';
$html = file_get_contents($url);
$p = '/<textarea[^>]*?>(.*?)<\/textarea>/s';
$strHtml= '/<div[^>]*?>(.*)<\/div>/s';
preg_match($p, $html, $match);
$str = $match[1];
function replaceUnnecessary($strJs)
{
$str = str_replace(""", "", $strJs);
$str = str_replace("{", "{\"", $str);
$str = str_replace(":", "\":\"", $str);
$str = str_replace(":\"{", ":{", $str);
$str = str_replace(",", "\",\"", $str);
$str = str_replace("}\",", "},", $str);
$str = str_replace("},", "\"},", $str);
$str = str_replace("\":\"{", "\":{", $str);
$str = str_replace("]\"", "]", $str);
$str = str_replace("\"[", "[", $str);
$str = str_replace("}]", "\"}]", $str);
return str_replace("}}", "\"}}", $str);
}
function httPreg($matches)
{
$sub = str_replace("\"", "", $matches[1]);
return "\":\"" . $sub . "\",\"";
}
$str = preg_replace_callback('/\":\"([^\{\}\]\[]*?)\",\"/', "httPreg", replaceUnnecessary($str));
$jsonData = json_decode($str);
//标的企业名称
echo $jsonData->utrgcemspreobject->objectname . "\n";
//法定代表人
echo $jsonData->utrgcemspreobject->objectboss . "\n";
//注册资本
echo $jsonData->utrgcemspreobject->registeredcapital . "\n";
//经济类型
echo $jsonData->utrgcemspreobject->economytype . "\n";
//企业类型
echo $jsonData->utrgcemspreobject->economynature . "\n";
//经济规模
echo $jsonData->utrgcemspreobject->managerscale . "\n";
//经营范围
echo $jsonData->utrgcemspreobject->businessscope . "\n";
网友评论