1、下载【phpQuery】,网上自行查找
2、把下载好的文件找到phpQuery.php文件的目录,把改目录的所有文件复制到项目指定文件夹
示例:【CI】框架
/** *------------------------------------- * @Function soccerDataEnd * @Author acclea * @Date 2019/5/15 * @Time 10:56:11 * @Describe 已经结束的比赛 * @Param int|string * @Return array|string *------------------------------------- */ public function soccerDataEnd(){ $dates = $this->input->get("dates"); if(!$dates){ $dates = date("Y-m-d");} // if($dates != date("Y-m-d",strtotime($dates))){ error("日期有误"); } header( 'Content-Type:text/html;charset=utf-8'); $url = "https://info.sporttery.cn/football/match_result.php?"; $param = "start_date=2019-05-01&end_date=2019-05-01&search_league=0"; // $param = "start_date=$dates&end_date=$dates&search_league=0"; require dirname(dirname(__FILE__)).("/libraries/phpQuery.php"); phpQuery::newDocumentFile($url.$param); $table = pq(".m-tab tr"); $objArr = array(); foreach($table as $trKey => $tr){ if($trKey == count($table) -2){break;} $matchTime = pq($tr)->find("td:eq(0)")->html(); $matchName = pq($tr)->find("td:eq(2)")->attr("title"); $masterTeam = pq($tr)->find("td:eq(3) span:eq(0)")->attr("title"); $rangqiu = pq($tr)->find("td:eq(3) span:eq(0)")->html(); $rangqiu = iconv('GBK', 'UTF-8', $rangqiu); $guestTeam = pq($tr)->find("td:eq(3) span:eq(2)")->attr("title"); $resultHalf = pq($tr)->find("td:eq(4) span:eq(0)")->html(); $resultAll = pq($tr)->find("td:eq(5) span:eq(0)")->html(); $hostWin = pq($tr)->find("td:eq(6) span:eq(0)")->html(); $dogfall = pq($tr)->find("td:eq(7) span:eq(0)")->html(); $guestWin = pq($tr)->find("td:eq(8) span:eq(0)")->html(); $objVal = array( 'matchTime' => $matchTime, 'matchName' => $matchName, 'masterTeam' => $masterTeam, 'rangqiu' => $rangqiu, 'guestTeam' => $guestTeam, 'resultHalf' => $resultHalf, 'resultAll' => $resultAll, 'hostWin' => $hostWin, 'dogfall' => $dogfall, 'guestWin' => $guestWin, 'addtime' => time(), 'times' => $dates ? strtotime($dates) : time(), ); $objArr[] = $objVal; } $finishFile = dirname(dirname(dirname(__FILE__))).("/grasp/finish-$dates.json"); $finishMatch = fopen($finishFile, "w") or die("Unable to open file!"); fwrite($finishMatch, json_encode($objArr,JSON_PRETTY_PRINT)); fclose($finishMatch); //打印 echo "<pre>?"; print_r($objArr); }
3、乱码处理
$content = mb_convert_encoding($content,'ISO-8859-1','utf-8'); $content = mb_convert_encoding($content,'utf-8','GBK');