簡體   English   中英

PHP爬網程序未爬網所有元素

[英]PHP Crawler not crawling all elements

所以我正在嘗試制作一個PHP搜尋器(供個人使用)。 該代碼的作用是為每個發現在不到1小時內結束的eBay拍賣項目顯示“找到”,但似乎存在問題。 搜尋器無法獲取所有span元素,而“ remaining time”元素為。

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';
        }
    }
    ?>

任何答案都會有用,在此先感謝

看着獲取的HTML,似乎是通過JavaScript設置了alert60Red類。 所以您找不到它,因為從未執行過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';
        }
    }

如果另一段php文件中包含一小段代碼,或者php中嵌入了html,則您的瀏覽器將看不到它。

因此,沒有任何Webcrawl api可以檢測到它。 我認為您最好的選擇是找到simple_html_Dom.php的位置,然后嘗試以某種方式爬網該文件。 您甚至可能無法訪問它。 這很棘手。

您還可以嘗試通過ID查找,如果您的api具有該功能?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM