이 코드를 통해 특정 텍스트를 얻을 수 있지만 내 문제는이 코드를 통해 웹 사이트에서 특정 사진을 얻는 방법입니다. 누구든지 도울 수 있습니까? 나는이 시점에 갇혀 있습니다.
<?php
ini_set('max_execution_time', 300);
function news($url,$path){
$curl=curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$html=curl_exec($curl);
if(!empty($curl)){
$thispage= new DOMDocument;
libxml_use_internal_errors(true);
$thispage->loadHTML($html);
libxml_clear_errors();
$xpath=new DOMXPath($thispage);
$status=$xpath->evaluate($path);
return $status;
}
}
$a= news('https://www.dawn.com/latest-news','string(/html/body/div[2]/div/main/div/div/div[1]/article[1]/h2/a)');
echo $a;
?>
첫 번째 헤드 라인 옆에 이미지가 나타나기를 원한다고 가정하면 XPath는 다음과 같습니다.
function news($url,$path){
$curl=curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$html=curl_exec($curl);
if(!empty($curl)){
$thispage= new DOMDocument;
libxml_use_internal_errors(true);
$thispage->loadHTML($html);
libxml_clear_errors();
$xpath=new DOMXPath($thispage);
$status=$xpath->evaluate($path);
return $status;
}
}
$a= news('https://www.dawn.com/latest-news','string(/html/body/div[2]/div/main/div/div/div[1]/article[1]/figure/div/a/img/@src)');
echo $a;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다