2016-07-24 4 views
0

그래서 PHP 크롤러 (개인용)를 만들려고합니다. 코드에서 1 시간 이내에 종료되지만 문제가있는 것으로 예상되는 각 eBay 경매 항목에 대해 "found"가 표시됩니다. 크롤러는 모든 span 요소를 가져올 수 없으며 "remaining time"요소는 다음과 같습니다.PHP 크롤러는 모든 요소를 ​​크롤링하지 않습니다.

simple_html_dom.php가 다운로드되고 편집되지 않습니다.

<?php include_once('simple_html_dom.php'); 

//url which i want to crawl -contains GET DATA- 

    $url = 'http://www.ebay.de/sch/Apple-Notebooks/111422/i.html?LH_Auction=1&Produktfamilie=MacBook%7CMacBook%2520Air%7CMacBook%2520Pro%7C%21&LH_ItemCondition=1000%7C1500%7C2500%7C3000&_dcat=111422&rt=nc&_mPrRngCbx=1&_udlo&_udhi=20'; 

    $html = new simple_html_dom(); 
    $html->load_file($url); 
    foreach($html->find('span') as $part){ 
     echo $part; 
//when i echo $part it does display many span elements but not the remaining time ones 
     $cur_class = $part->class; 

//the class attribute of an auction item that ends in less than an hour is equal with "MINUTES timeMs alert60Red" 
     if($cur_class == 'MINUTES timeMs alert60Red'){ 
      echo 'found'; 
     } 
    } 
    ?> 

모든 대답은,이 클래스 alert60Red는 자바 스크립트를 통해 설정되어있는 경우로 보인다 가져온 HTML을 보면 미리

+0

echo $ html; 정상적으로 모든 요소를 ​​표시하고, 무언가 이해가되지 않는다면 유감스럽게 생각합니다. 제 질문은 여기에 있습니다. –

답변

0

에 감사 유용 할 것이다. JavaScript가 실행되지 않으므로 찾을 수 없습니다.

따라서 MINUTES timeMs을 검색하면 안정적으로 보입니다.

<?php 
    include_once('simple_html_dom.php'); 

    $url = 'http://www.ebay.de/sch/Apple-Notebooks/111422/i.html?LH_Auction=1&Produktfamilie=MacBook%7CMacBook%2520Air%7CMacBook%2520Pro%7C%21&LH_ItemCondition=1000%7C1500%7C2500%7C3000&_dcat=111422&rt=nc&_mPrRngCbx=1&_udlo&_udhi=20'; 

    $html = new simple_html_dom(); 
    $html->load_file($url); 
    foreach ($html->find('span') as $part) { 
     $cur_class = $part->class; 

     if (strpos($cur_class, 'MINUTES timeMs') !== false) { 
      echo 'found'; 
     } 
    } 
+0

고마워, 몇 시간 동안 나를 괴롭혔다. –

0

코드 스 니펫이 다른 PHP 파일에 포함되어 있거나 HTML이 PHP에 포함되어 있으면 브라우저에서 볼 수 없습니다.

그래서 웹 크롤링 API가이를 감지 할 수 없습니다. 가장 좋은 방법은 simple_html_Dom.php의 위치를 ​​찾고 그 파일을 어떻게 든 크롤링 해보는 것입니다. 당신은 심지어 그것에 접근 할 수 없을지도 모릅니다. 까다 롭습니다.

API에 해당 기능이 있는지 ID를 찾아 볼 수도 있습니다.