douna2014 2015-07-28 19:51
浏览 264
已采纳

Dom解析器和Google图像结果

I am trying to retrieve Google image results/links with php dom parser. The code I have just written run without error, but I do not see any results( i.e. links) outputting to my browser. Can you help me find out the problem? I cannot figure out.

Here is my script:

<?php
    include_once __DIR__.'/simple_html_dom.php';

    $name = '"michael jackson"';
    $query = urlencode($name); 
    $url = "https://www.google.com/search?q={$query}&tbm=isch&tbs=ic:color,isz:lt,islt:4mp,itp:face,isg:to";

    // Create DOM from URL or file
    $html = file_get_html($url);

    // Find all images
    $linkObjs = $html->find("div[class=rg_di rg_el ivg-i] a");
    foreach ($linkObjs as $linkObj) {
        $link = trim($linkObj->href);
        echo $link . '<br>';
    }
?>
  • 写回答

1条回答 默认 最新

  • dtuct88226 2015-07-28 22:01
    关注

    You get a different DOM structure in the browser (processed) than the one you get as plain html. Output the content of $html and you will see. You need to adapt your selector.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题