After playing with curl, I found that php regularization is really important, but unfortunately I am very bad at it. I took three fields on the web page and wrote a demo. Copy the code posted below and run it directly. In fact, it is an idea of using other people's data to make your own API. <?php <br />
function getwebcontent($url){ <br>
$ch = curl_init(); <br>
curl_setopt($ch, CURLOPT_URL, $url); <br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); <br>
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); <br>
$contents = trim(curl_exec($ch)); <br>
curl_close($ch); <br>
Return $contents; <br>
} <br>
function DeleteHtml($str) { <br>
$str = trim($str); <br>
$str = str_replace("t","",$str); <br>
$str = str_replace("rn","",$str); <br>
$str = str_replace("r","",$str); <br>
$str = str_replace("n","",$str); <br>
Return trim($str); <br>
}<br>
set_time_limit(0);<br>
$datas =DeleteHtml(getwebcontent('http://www.jin10.com')); <br>
Preg_match_all('/(d{2}:d{2})/',$datas,$time); /*All corresponding times*/<br>
preg_match_all('/<td>]+?ids*?=s*?"content_d+?">(.+?)</td>/',$datas,$content); /*Corresponding All content*/<br>
Preg_match_all('/"General news"|"Important news"|"General data"|"Important data"/',$datas,$importance); /*The importance of all corresponding news*/<br>
$contents=$content[1]; /*All corresponding contents*/<br>
$times=$time[1]; /*All corresponding times*/<br>
$importances=$importance[0];<br>
<br>
$news=[];<br>
foreach ($contents as $key => $value) {<br>
$t=[<br>
"content"=>$value,<br>
"time"=>$times[$key],<br>
“Importance”=>str_replace('"','',$importances[$key]),<br>
];<br>
array_push($news,$t);<br>
}<br>
var_dump($news);<br>
<br>
?>
109news.rar ( 1.12 MB Download: 7 times )