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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题