最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP CURL采集百度搜尋結果圖片不顯示問題的解決方法

 更新時間:2017年02月03日 10:08:30   作者:傲雪星楓  
這篇文章主要介紹了PHP CURL采集百度搜尋結果圖片不顯示問題的解決方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

1.根據(jù)關鍵字采集百度搜尋結果

根據(jù)關鍵字采集百度搜尋結果,可以使用curl實現(xiàn),代碼如下:

<?php
function doCurl($url, $data=array(), $header=array(), $timeout=30){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  $response = curl_exec($ch);
  if($error=curl_error($ch)){
    die($error);
  }
  curl_close($ch);
  return $response;
}
$wd = '仙劍奇?zhèn)b傳';
$url = 'http://www.baidu.com/s?wd='.urlencode($wd);
$data = array();
$header = array();
$response = doCurl($url, $data, $header, 5);
echo $response;
?>

輸出后發(fā)現(xiàn)有部分圖片不能顯示

這里寫圖片描述 

2.采集后的圖片不顯示原因分析

直接在百度中搜尋,頁面是可以顯示圖片的。使用firebug查看圖片路徑,發(fā)現(xiàn)采集的圖片域名與在百度搜尋的圖片域名不同。

采集返回的圖片域名 t11.baidu.com

這里寫圖片描述 

正常搜尋的圖片域名 ss1.baidu.com

這里寫圖片描述 

查看采集與正常搜尋的html,發(fā)現(xiàn)有個域名轉換的js是不一樣的

采集

var list = {
    "graph.baidu.com": "http://graph.baidu.com",
    "t1.baidu.com":"http://t1.baidu.com",
    "t2.baidu.com":"http://t2.baidu.com",
    "t3.baidu.com":"http://t3.baidu.com",
    "t10.baidu.com":"http://t10.baidu.com",
    "t11.baidu.com":"http://t11.baidu.com",
    "t12.baidu.com":"http://t12.baidu.com",
    "i7.baidu.com":"http://i7.baidu.com",
    "i8.baidu.com":"http://i8.baidu.com",
    "i9.baidu.com":"http://i9.baidu.com",
};

正常搜尋

var list = {
    "graph.baidu.com": "https://sp0.baidu.com/-aYHfD0a2gU2pMbgoY3K",
    "t1.baidu.com":"https://ss0.baidu.com/6ON1bjeh1BF3odCf",
    "t2.baidu.com":"https://ss1.baidu.com/6OZ1bjeh1BF3odCf",
    "t3.baidu.com":"https://ss2.baidu.com/6OV1bjeh1BF3odCf",
    "t10.baidu.com":"https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq",
    "t11.baidu.com":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq",
    "t12.baidu.com":"https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq",
    "i7.baidu.com":"https://ss0.baidu.com/73F1bjeh1BF3odCf",
    "i8.baidu.com":"https://ss0.baidu.com/73x1bjeh1BF3odCf",
    "i9.baidu.com":"https://ss0.baidu.com/73t1bjeh1BF3odCf",
};

因此可以斷定是,百度根據(jù)來源地址、IP、header等參數(shù),判斷如果是采集的,則返回不同的js。

3.采集后圖片不顯示的解決方法

把采集到的html,根據(jù)定義的域名做一次批量轉換即可。

<?php
function doCurl($url, $data=array(), $header=array(), $timeout=30){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  $response = curl_exec($ch);
  if($error=curl_error($ch)){
    die($error);
  }
  curl_close($ch);
  return $response;
}
// 域名轉換
function cdomain($str){
  $baidu_domain = '{
    "http://graph.baidu.com": "https://sp0.baidu.com/-aYHfD0a2gU2pMbgoY3K",
    "http://p.qiao.baidu.com":"https://sp0.baidu.com/5PoXdTebKgQFm2e88IuM_a",
    "http://vse.baidu.com":"https://sp3.baidu.com/6qUDsjip0QIZ8tyhnq",
    "http://hdpreload.baidu.com":"https://sp3.baidu.com/7LAWfjuc_wUI8t7jm9iCKT-xh_",
    "http://lcr.open.baidu.com":"https://sp2.baidu.com/8LUYsjW91Qh3otqbppnN2DJv",
    "http://kankan.baidu.com":"https://sp3.baidu.com/7bM1dzeaKgQFm2e88IuM_a",
    "http://xapp.baidu.com":"https://sp2.baidu.com/yLMWfHSm2Q5IlBGlnYG",
    "http://dr.dh.baidu.com":"https://sp0.baidu.com/-KZ1aD0a2gU2pMbgoY3K",
    "http://xiaodu.baidu.com":"https://sp0.baidu.com/yLsHczq6KgQFm2e88IuM_a",
    "http://sensearch.baidu.com":"https://sp1.baidu.com/5b11fzupBgM18t7jm9iCKT-xh_",
    "http://s1.bdstatic.com":"https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K",
    "http://olime.baidu.com":"https://sp0.baidu.com/8bg4cTva2gU2pMbgoY3K",
    "http://app.baidu.com":"https://sp2.baidu.com/9_QWsjip0QIZ8tyhnq",
    "http://i.baidu.com":"https://sp0.baidu.com/74oIbT3kAMgDnd_",
    "http://c.baidu.com":"https://sp0.baidu.com/9foIbT3kAMgDnd_",
    "http://sclick.baidu.com":"https://sp0.baidu.com/5bU_dTmfKgQFm2e88IuM_a",
    "http://nsclick.baidu.com":"https://sp1.baidu.com/8qUJcD3n0sgCo2Kml5_Y_D3",
    "http://sestat.baidu.com":"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a",
    "http://eclick.baidu.com":"https://sp3.baidu.com/-0U_dTmfKgQFm2e88IuM_a",
    "http://api.map.baidu.com":"https://sp2.baidu.com/9_Q4sjOpB1gCo2Kml5_Y_D3",
    "http://ecma.bdimg.com":"https://ss1.bdstatic.com/-0U0bXSm1A5BphGlnYG",
    "http://ecmb.bdimg.com":"https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG",
    "http://t1.baidu.com":"https://ss0.baidu.com/6ON1bjeh1BF3odCf",
    "http://t2.baidu.com":"https://ss1.baidu.com/6OZ1bjeh1BF3odCf",
    "http://t3.baidu.com":"https://ss2.baidu.com/6OV1bjeh1BF3odCf",
    "http://t10.baidu.com":"https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq",
    "http://t11.baidu.com":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq",
    "http://t12.baidu.com":"https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq",
    "http://i7.baidu.com":"https://ss0.baidu.com/73F1bjeh1BF3odCf",
    "http://i8.baidu.com":"https://ss0.baidu.com/73x1bjeh1BF3odCf",
    "http://i9.baidu.com":"https://ss0.baidu.com/73t1bjeh1BF3odCf",
    "http://b1.bdstatic.com":"https://ss0.bdstatic.com/9uN1bjq8AAUYm2zgoY3K",
    "http://ss.bdimg.com":"https://ss1.bdstatic.com/5aV1bjqh_Q23odCf",
    "http://opendata.baidu.com":"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv",
    "http://api.open.baidu.com":"https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv",
    "http://tag.baidu.com":"https://sp1.baidu.com/6LMFsjip0QIZ8tyhnq",
    "http://f3.baidu.com":"https://sp2.baidu.com/-uV1bjeh1BF3odCf",
    "http://s.share.baidu.com":"https://sp0.baidu.com/5foZdDe71MgCo2Kml5_Y_D3",  
    "http://bdimg.share.baidu.com":"https://ss1.baidu.com/9rA4cT8aBw9FktbgoI7O1ygwehsv",
    "http://1.su.bdimg.com":"https://ss0.bdstatic.com/k4oZeXSm1A5BphGlnYG",
    "http://2.su.bdimg.com":"https://ss1.bdstatic.com/kvoZeXSm1A5BphGlnYG",
    "http://3.su.bdimg.com":"https://ss2.bdstatic.com/kfoZeXSm1A5BphGlnYG",
    "http://4.su.bdimg.com":"https://ss3.bdstatic.com/lPoZeXSm1A5BphGlnYG",
    "http://5.su.bdimg.com":"https://ss0.bdstatic.com/l4oZeXSm1A5BphGlnYG",
    "http://6.su.bdimg.com":"https://ss1.bdstatic.com/lvoZeXSm1A5BphGlnYG",
    "http://7.su.bdimg.com":"https://ss2.bdstatic.com/lfoZeXSm1A5BphGlnYG",
    "http://8.su.bdimg.com":"https://ss3.bdstatic.com/iPoZeXSm1A5BphGlnYG"
  }';
  $domain = json_decode($baidu_domain, true);
  foreach($domain as $k=>$v){
    $str = str_replace($k, $v, $str);
  }
  return $str;
}
$wd = '仙劍奇?zhèn)b傳';
$url = 'http://www.baidu.com/s?wd='.urlencode($wd);
$data = array();
$header = array();
$response = doCurl($url, $data, $header, 5);
echo cdomain($response); // 調用域名轉換
?>

增加域名轉換后,所有的圖片都可以正常顯示。

這里寫圖片描述

以上所述是小編給大家介紹的PHP CURL采集百度搜尋結果圖片不顯示問題的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • 一個PHP針對數(shù)字的加密解密類

    一個PHP針對數(shù)字的加密解密類

    這篇文章主要介紹了一個PHP針對數(shù)字的加密解密類,該類僅支持加密數(shù)字。比較適用于數(shù)據(jù)庫中id字段的加密解密,以及根據(jù)數(shù)字顯示url的加密,需要的朋友可以參考下
    2014-03-03
  • php反序列化長度變化尾部字符串逃逸(0CTF-2016-piapiapia)

    php反序列化長度變化尾部字符串逃逸(0CTF-2016-piapiapia)

    這篇文章主要介紹了0CTF-2016-piapiapia(php反序列化長度變化尾部字符串逃逸),本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-02-02
  • Yii2使用小技巧之通過 Composer 添加 FontAwesome 字體資源

    Yii2使用小技巧之通過 Composer 添加 FontAwesome 字體資源

    前天幫同事改個十年前的網(wǎng)站 bug,頁面上一堆 include require 不禁讓人抱頭痛哭??吹?V2EX 上的討論說,寫 PHP 不用框架等同于耍流氓。Yii Framework 是我使用了 2 年多的 PHP 框架,器大活好,皮實耐操。 Yii2 還在 Beta 中,不過不影響拿來預研。
    2014-06-06
  • 利用php做服務器和web前端的界面進行交互

    利用php做服務器和web前端的界面進行交互

    PHP與Web頁面交互是實現(xiàn)PHP網(wǎng)站與用戶交互的重要手段。本篇文章主要介紹了利用php做服務器和web前端的界面進行交互,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2016-10-10
  • Laravel利用gulp如何構建前端資源詳解

    Laravel利用gulp如何構建前端資源詳解

    Gulp 是一個自動化工具,前端開發(fā)者可以使用它來處理常見任務,下面這篇文章主要給大家介紹了關于Laravel利用gulp如何構建前端資源的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧
    2018-06-06
  • php中存儲用戶ID和密碼到mysql數(shù)據(jù)庫的方法

    php中存儲用戶ID和密碼到mysql數(shù)據(jù)庫的方法

    對用戶身份驗證,最常用的方法就是將用戶id與密碼保存進數(shù)據(jù)庫中了,然后再寫一些登錄檢測代碼,就可以使用了
    2013-02-02
  • PHP實現(xiàn)中國公民身份證號碼有效性驗證示例代碼

    PHP實現(xiàn)中國公民身份證號碼有效性驗證示例代碼

    這篇文章主要介紹了PHP實現(xiàn)中國公民身份證號碼有效性驗證示例代碼,可以判斷身份證號碼的正確性,非常具有實用價值
    2017-05-05
  • 詳解PHP編碼轉換函數(shù)應用技巧

    詳解PHP編碼轉換函數(shù)應用技巧

    在PHP語言中mb_convert_encoding是一個PHP編碼轉換函數(shù),可以幫助我們用來實現(xiàn)對多字節(jié)字符串編碼的轉換。下面將會為大家進行詳細介紹。
    2016-10-10
  • ThinkPHP框架整合微信支付之刷卡模式圖文詳解

    ThinkPHP框架整合微信支付之刷卡模式圖文詳解

    這篇文章主要介紹了ThinkPHP框架整合微信支付之刷卡模式,結合圖文形式詳細分析了thinkPHP框架整合微信支付的刷卡模式實現(xiàn)步驟與相關操作技巧,需要的朋友可以參考下
    2019-04-04
  • Drupal簡體中文語言包安裝教程

    Drupal簡體中文語言包安裝教程

    這篇文章主要介紹了Drupal簡體中文語言包安裝教程,本文講解了Drupal中文語言包的安裝步驟,需要的朋友可以參考下
    2014-09-09

最新評論

开封县| 鹰潭市| 茶陵县| 通州区| 黄骅市| 建宁县| 虞城县| 彰武县| 漠河县| 卢龙县| 甘南县| 定西市| 图们市| 湾仔区| 胶州市| 尤溪县| 莫力| 错那县| 陈巴尔虎旗| 龙井市| 宁德市| 获嘉县| 皮山县| 太白县| 宜君县| 盈江县| 海丰县| 隆昌县| 洪洞县| 陆川县| 额尔古纳市| 桃江县| 治多县| 毕节市| 竹北市| 宁明县| 庄浪县| 仙桃市| 堆龙德庆县| 卫辉市| 资中县|