이것은 http://www.partyhousedecorations.com 에서 특정 데이터를 긁어내는 데 사용하는 코드 이지만이 오류가 계속 발생하고 ( Fatal error: Call to a member function children() on a non-object in C:\wamp\www\webScraping\PartyHouseDecorations.php on line 8
) 멈춰서 수정할 수없는 것 같습니다. 이것은 내 코드입니다.
<?php
include_once("simple_html_dom.php");
$serv=$_GET['search'];
$url = 'http://www.partyhousedecorations.com/category-adult-birthday-party-themes'.$serv;
$output = file_get_html($url);
$arrOfStuff = $output->find('div[class=product-grid]', 0)->children();
foreach( $arrOfStuff as $item )
{
echo "Party House Decorations".'<br>';
echo $item->find('div[class=name]', 0)->find('a', 0)->innertext.'<br>';
echo '<img src="http://www.partyhousedecorations.com'.$item->find('div[class=image]', 0)->find('img', 0)->src.'"><br>';
echo str_replace('KWD', 'AED', $item->find('div[class=price]',0)->innertext.'<br>');
}
?>
$output->find('div[class=product-grid]', 0)
라는 메서드로 객체를 반환하지 않는 것 같습니다 children()
. null 또는 객체가 아닌 무언가를 반환 할 수 있습니다. 별도의 변수에 넣고 해당 변수의 값이 무엇인지 확인하십시오.
$what_is_this = $output->find('div[class=product-grid]', 0);
var_dump($what_is_this)
최신 정보:
나는 당신의 프로그램을 디버깅했고, 단순한 html dom 파서와는 별도로 클래스가 주어질 것으로 예상 'div.product-grid'
하는 'div[class=x]'
것 외에도 웹 페이지가 제품 그리드 대신 제품 목록을 반환하여 응답하는 것으로 나타났습니다. 아래에 작업 사본을 포함했습니다.
<?php
include_once("simple_html_dom.php");
$serv=$_GET['search'];
$url = 'http://www.partyhousedecorations.com/category-adult-birthday-party-themes';
$output = file_get_html($url);
$arrOfStuff = $output->find('div.product-list', 0)->children();
foreach( $arrOfStuff as $item )
{
echo "Party House Decorations".'<br>';
echo $item->find('div.name', 0)->find('a', 0)->innertext.'<br>';
echo '<img src="http://www.partyhousedecorations.com'.$item->find('div.image', 0)->find('img', 0)->src.'"><br>';
echo str_replace('KWD', 'AED', $item->find('div.price',0)->innertext.'<br>');
}
?>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다