溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何在php中使用curl抓取新浪微博內(nèi)容

發(fā)布時(shí)間:2021-01-21 15:44:12 來源:億速云 閱讀:230 作者:Leah 欄目:開發(fā)技術(shù)

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)如何在php中使用curl抓取新浪微博內(nèi)容,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

代碼如下:


<?php
  set_time_limit(0);
  $url="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=550&fansRow=2&ptype=1&speed=0&skin=1&isTitle=1&noborder=1&isWeibo=1&isFans=1&uid=1724077823&verifier=8738a0fa&dpc=1"; //微博秀地址
  $ch=curl_init();
  curl_setopt($ch,CURLOPT_HEADER,false);
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  $content=curl_exec($ch);
  curl_close($ch);
  preg_match_all('/<p class="weiboShow_mainFeed_listContent_txt">(.*)<\/p>/iUs',$content,$text);//獲取文字
  preg_match_all('/<span class="weiboShow_mainFeed_listContent_actionTime">(.*)<\/span>/iUs',$content,$time);//獲取時(shí)間
  $me=explode('<div class="weiboShow_developer_pic">',$content);
  $me=explode('</div>',$me[1]);
  preg_match_all("/src=\"([^\"].*)\"/iUs",$me[0],$avatar);//獲取我的頭像

  $a=$text[0];
  $b=$time[0];
  $result=array_combine($a, $b);//合并數(shù)組
  foreach($result as $text=>$time){
    echo "<img src='".$avatar[1][0]."' height='50'/>";
    echo strip_tags($text);
    echo strip_tags($time);
  }
?>

上述就是小編為大家分享的如何在php中使用curl抓取新浪微博內(nèi)容了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI