dongyou5271 2014-11-06 22:03
浏览 28

无法通过php阅读aliexpress.com

I'm trying to read aliexpress.com deals page via php. I'm not able to get the details of the page in output.

Is there a way I can get the details.

Below is the code.

<?php
    include('simple_html_dom.php');
    $url = 'http://activities.aliexpress.com/superdeals.php';
    $xml = file_get_html($url);
    //$file = 'output1.txt';
    $element = $xml;
    echo $element;
?>
  • 写回答

1条回答 默认 最新

  • dslk6326846 2014-11-07 00:20
    关注

    This website used AJAX
    There are two solutions :
    - Make the same request as Javascript
    - Using a tool like Phantomjs

    If you look at requests, you will find easily that a GET request is made and return all information in JSON. So you need to find by yourself the link or use third party library + tools.

    EDIT:

    You can use your web browser to get the link (I don't give you it because i think stackoverflow is not for that) with firebug or if you're using chrome, in network tab search for the JSON.

    $url = "....";
    $str = file_get_contents($url);
    if($str) {
        $json = json_decode($str, true); // json is an array
        // ... do what you need
    }
    

    I recommend to use curl instead of file_get_contents for many reasons.

    Or you can use Phantomjs (it's really more difficult) and get a "HTML snapshot" and then use DOM or XPATH to get what you need, but you must run Phantomjs and use a third party library for communicate with it.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程