首頁 > 後端開發 > php教程 > php curl抓取新浪微博内容_PHP教程

php curl抓取新浪微博内容_PHP教程

WBOY
發布: 2016-07-13 10:31:45
原創
1029 人瀏覽過

很多人都喜欢在网站上DIY自己的微博,所以我也写了一个。
这里直接抓取了新浪微博工具中的微博秀地址。

<?<span php

  </span><span set_time_limit</span>(0<span );
  </span><span $url</span>="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"; <span //</span><span 微博秀地址</span>
  <span $ch</span>=<span curl_init();
  curl_setopt(</span><span $ch</span>,CURLOPT_HEADER,<span false</span><span );
  curl_setopt(</span><span $ch</span>,CURLOPT_URL,<span $url</span><span );
  curl_setopt(</span><span $ch</span>,CURLOPT_RETURNTRANSFER,1<span );
  </span><span $content</span>=curl_exec(<span $ch</span><span );
  curl_close(</span><span $ch</span><span );
  </span><span preg_match_all</span>('/<p class="weiboShow_mainFeed_listContent_txt">(.*)<\/p>/iUs',<span $content</span>,<span $text</span>);<span //</span><span 获取文字</span>
  <span preg_match_all</span>('/<span class="weiboShow_mainFeed_listContent_actionTime">(.*)<\/span>/iUs',<span $content</span>,<span $time</span>);<span //</span><span 获取时间</span>
  <span $me</span>=<span explode</span>('<div class="weiboShow_developer_pic">',<span $content</span><span );
  </span><span $me</span>=<span explode</span>('</div>',<span $me</span>[1<span ]);
  </span><span preg_match_all</span>("/src=\"([^\"].*)\"/iUs",<span $me</span>[0],<span $avatar</span>);<span //</span><span 获取我的头像
 //  www.jbxue.com</span>

  <span $a</span>=<span $text</span>[0<span ];
  </span><span $b</span>=<span $time</span>[0<span ];
  </span><span $result</span>=<span array_combine</span>(<span $a</span>, <span $b</span>);<span //</span><span 合并数组</span>
  <span foreach</span>(<span $result</span> <span as</span> <span $text</span>=><span $time</span><span ){
    </span><span echo</span> "<img  src='".<span $avatar</span alt="php curl抓取新浪微博内容_PHP教程" >[1][0]."'    style="max-width:90%"/>"<span ;
    </span><span echo</span> <span strip_tags</span>(<span $text</span><span );
    </span><span echo</span> <span strip_tags</span>(<span $time</span><span );
  }
</span>?>
登入後複製

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/761776.htmlTechArticle很多人都喜欢在网站上DIY自己的微博,所以我也写了一个。 这里直接抓取了新浪微博工具中的微博秀地址。 ? (0 ="http://widget.weibo.com/weibos...
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板