외부 소스에서 데이터를 가져 오려고하는데 데이터를 가져올 수없고이 오류가 발생합니다.데이터 추출시 멤버 함수 오류가 발생했습니다.
Notice: Trying to get property of non-object in E:\xampp\htdocs\test\merit-list.php on line 38 Fatal error: Call to a member function find() on null in E:\xampp\htdocs\test\merit-list.php on line 39
여기에 문제는이 제목의 행이기 때문에 테이블의 첫 번째 행은 그래서, $div->find("img", 0)
반환 null
을 <img>
이 없음을 내 코드
<?php
require('resources/inc/simple_html_dom.php');
$linksrc = 'http://58.65.172.36/Portal/WebSiteUpdates/Achievements.aspx';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $linksrc,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 3000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
));
$file = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
$dom = new simple_html_dom();
$dom->load($file);
$doctorDivs = $dom->find("table#Farooq", 0)->children();
$doctors = array();
foreach($doctorDivs as $div){
$doctor = array();
// line 38
$image = $doctor["image"] = $div->find('img', 0)->src;
$details = $div->find('tr', 0)->find("td");
$name = $doctor["name"] = trim($details[1]->plaintext);
$spec = $doctor["desc"] = trim($details[2]->plaintext);
$doctors[] = $doctor;
echo $image;
echo $name;
echo $spec;
}
?>
은 컨트롤이 foreach 루프 안으로 들어가 있습니까? –
그래, 외부 링크에서 데이터를 얻고 싶다. # Farooq 테이블 안의 모든 이미지 텍스트 등을 의미하지만, 주요 문제점을 이해하지 못한다. –
객체가 아닌 객체의 속성을 가져 오려고하면 null이됩니다. 38 번 라인은 정확히 무엇입니까? 해당 줄에 주석을 달아 어떤 줄이 있는지 알 수 있습니다. –