หัวข้อ: ช่วยหน่อยครับเรื่อง curl มันดึงข้อมูลมาไม่ครบ +1
เริ่มหัวข้อโดย: WP-design ที่ 14 กรกฎาคม 2018, 10:14:08
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://sport.mthai.com/league-table/bundes-liga"); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 45); $html_result = curl_exec($ch); curl_close($ch); $dom = new DOMDocument(); @$dom->loadHTML($html_result); $xpath = new DOMXPath($dom); $start_result = strpos($html_result,'<div class="table-scroll">'); $end_result = strpos($html_result,'</div>',$start_result); echo substr($html_result,$start_result,$end_result-$start_result);
?>
ผมจะดึงตารางคะแนนจากเว็บ https://sport.mthai.com/league-table/bundes-liga แต่แท็กปิด </div> มันไม่มาครับผมต้องแก้ยังไงครับ มันมาเริ่มจาก <div class="table-scroll"> แต่แท็กปิด </div> มันหายไปครับ
หัวข้อ: Re: ช่วยหน่อยครับเรื่อง curl มันดึงข้อมูลมาไม่ครบ +1
เริ่มหัวข้อโดย: amarin.ta ที่ 14 กรกฎาคม 2018, 15:18:03
ลองดูนะครับ <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://sport.mthai.com/league-table/bundes-liga"); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 45); $html_result = curl_exec($ch); curl_close($ch);
$html_result = preg_replace("/[\n\r]/","",$html_result); preg_match('/<div class="table-scroll">(?:.*?)<\/div>/m',$html_result,$match); $divResult = $match[0]; echo $divResult;
?>
|