dongzhang8475 2015-02-11 13:32
浏览 48
已采纳

使用带有ajax的simple_html_dom [重复]

This question already has an answer here:

I'm doing the Parser of a page with the 'simple_html_dom' library however not got success to parse an html whose content is obtained through ajax. is there any way around this?

PHP Code:

<?php
require_once '../library/Simple_HTML_DOM/simple_html_dom.php';

// Create DOM from URL or file
$html = file_get_html('http://www.playnow3dgames.com/genre.php?id=sports');

// Find all images 
foreach($html->find('img') as $element){
echo $element->src . '<br>';
}
?>

Only prints the images on the edges and top (html native) and Is not parsed the center images (using ajax).

</div>
  • 写回答

1条回答 默认 最新

  • dongsheng8664 2015-02-11 13:38
    关注

    try with this

    <?php
    require_once '../library/Simple_HTML_DOM/simple_html_dom.php';
    
    // Create DOM from URL or file
    $html = file_get_html('http://www.playnow3dgames.com/listing.php?genre=sports&order=date');
    
    // Find all images 
    foreach($html->find('img') as $element){
        echo $element->src . '<br>';
    }
    ?>
    

    === UPDATE ====

    actualy, this a iframe, it is not ajax. in center of http://www.playnow3dgames.com/genre.php?id=sports is frame: http://www.playnow3dgames.com/listing.php?genre=sports&order=date

    you can see struct of url:

    http://www.playnow3dgames.com/listing.php?genre=sports&order=date
    

    at here: genre=sports

    this is real url: http://www.playnow3dgames.com/genre.php?id=sports

    you will see match of id=sports with genre=sports

    to get for every pages, you only need change genre=genre_name. for example:

    http://www.playnow3dgames.com/genre.php?id=strategy
    

    the main frame will be:

    www.playnow3dgames.com/listing.php?genre=strategy&order=date
    

    if you want to get page 1,2,3..., you need add page=page_number. for example: get page 2 of

    http://www.playnow3dgames.com/genre.php?id=strategy
    

    url will be:

    http://www.playnow3dgames.com/listing.php?genre=strategy&page=2&order=date
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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代码移植没反应