PHP採集網頁資訊

來源:互聯網
上載者:User
【求助】PHP採集網頁資訊
需要採集
http://bbs.zhanzhang.baidu.com/home.php?mod=space&uid=*
不同UID的使用者名稱
不熟悉PHP以及正則,只是單純的想要結果,所以麻煩直接給出PHP代碼和前1000個UID的使用者名稱,謝謝。 php


------解決方案--------------------
$html = file_get_contents('http://bbs.zhanzhang.baidu.com/home.php?mod=space&uid=1');
preg_match('@

(.*?)<\/h2>@',$html,$match);
//var_dump($match);
echo strip_tags($match[0]);


理論上uid是自增的,前1000個就是1-1000,數字自己換吧。
------解決方案--------------------
$url = 'http://bbs.zhanzhang.baidu.com/home.php?mod=space&uid=';

$res = array();
$uid = 1;
while(count($res) < 20) { //擷取前20個,自己根據需要修改
if(preg_match('//s', file_get_contents($url.$uid), $r)){
if(preg_match_all('/\w+/', strip_tags($r[0]), $r) == 3) {
$res[$r[0][2]] = $r[0][0];
}
}
$uid++;
}
print_r($res);
結果:(關聯鍵為UID,值為使用者名稱)

Array
(
[1] => sitemapbbs
[7] => _
[8] => sitemapTest2
[9] => sitemapTest
[10] => sitemapTest32
[13] => sitemapTest3
[14] => kkksuper
[16] => 05
[17] => caoli456
[18] => wangbin_ivan
[19] => geiwosou
[20] => sitemap_test1
[21] => sitemap_test5
[22] => _
[23] => lkmmmmj
[24] => blackfox1983
[25] => dongbei_wb
[26] => xyzlinger
[27] => sanwushuosi
[28] => 007
)

------解決方案--------------------
同上,不過file_get_contents方法有時候會太慢,可以採用curl.
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.