dongyao9762 2013-12-09 16:03
浏览 21
已采纳

PHP简单的HTML DOM Scrape外部URL

I'm trying to build a personal project of mine, however I'm a bit stuck when using the Simple HTML DOM class.

What I'd like to do is scrape a website and retrieve all the content, and it's inner html, that matches a certain class.

My code so far is:

    <?php
    error_reporting(E_ALL);
    include_once("simple_html_dom.php");
    //use curl to get html content
    $url = 'http://www.peopleperhour.com/freelance-seo-jobs';

    $html = file_get_html($url);

    //Get all data inside the <div class="item-list">
    foreach($html->find('div[class=item-list]') as $div) {
    //get all div's inside "item-list"
    foreach($div->find('div') as $d) {
    //get the inner HTML
    $data = $d->outertext;
    }
    }
print_r($data)
    echo "END";
    ?>

All I get with this is a blank page with "END", nothing else outputted at all.

  • 写回答

2条回答 默认 最新

  • dre26973 2013-12-09 16:15
    关注

    I think, you may want something like this

    $url = 'http://www.peopleperhour.com/freelance-seo-jobs';
    $html = file_get_html($url);
    foreach ($html->find('div.item-list div.item') as $div) {
        echo $div . '<br />';
    };
    

    This will give you something like this (if you add the proper style sheet, it'll be displayed nicely)

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应