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 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染