【问题标题】:PHP Crawler not crawling all elementsPHP Crawler 未抓取所有元素
【发布时间】:2016-07-24 21:38:58
【问题描述】:

所以我正在尝试制作一个 PHP 爬虫(供个人使用)。 代码的作用是为每个发现不到 1 小时但似乎有问题的 ebay 拍卖项目显示“找到”。爬虫无法获取所有 span 元素,“剩余时间”元素为 .

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;正常显示所有元素,如果有什么不明白的地方很抱歉,这是我在这里提出的第一个问题。

标签: php web-crawler simple-html-dom


【解决方案1】:

查看获取的 HTML,似乎 alert60Red 类是通过 JavaScript 设置的。所以你找不到它,因为 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';
        }
    }

【讨论】:

  • 非常感谢,这困扰了我好几个小时
【解决方案2】:

如果一个sn-p的代码包含在另一个php文件中,或者html嵌入在php中,你的浏览器看不到它。

所以没有 webcrawl api 可以检测到它。我认为您最好的选择是找到 simple_html_Dom.php 的位置并尝试以某种方式抓取该文件。您甚至可能无法访问它。这很棘手。

如果您的 api 具有该功能,您也可以尝试按 ID 查找?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2016-10-05
    • 1970-01-01
    相关资源
    最近更新 更多