ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: WP-design ที่ 14 กรกฎาคม 2018, 10:14:08



หัวข้อ: ช่วยหน่อยครับเรื่อง curl มันดึงข้อมูลมาไม่ครบ +1
เริ่มหัวข้อโดย: WP-design ที่ 14 กรกฎาคม 2018, 10:14:08

โค๊ด:
<?php
$ch 
curl_init();
curl_setopt($chCURLOPT_URL,"https://sport.mthai.com/league-table/bundes-liga");
curl_setopt($chCURLOPT_FAILONERRORtrue);
curl_setopt($chCURLOPT_AUTOREFERERtrue);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFER,true);
curl_setopt($chCURLOPT_TIMEOUT45);
$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($chCURLOPT_URL,"https://sport.mthai.com/league-table/bundes-liga");
curl_setopt($chCURLOPT_FAILONERRORtrue);
curl_setopt($chCURLOPT_AUTOREFERERtrue);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFER,true);
curl_setopt($chCURLOPT_TIMEOUT45);
$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;

?>