PHP collects webpage information

Source: Internet
Author: User
[Help] PHP collection page information need to collect & nbsp; http://bbs.zhanzhang.baidu.com/home.php? Mod = space & amp; uid = * the user names of different UIDs are not familiar with PHP and regular expressions, but they only want results. Therefore, you need to directly give the PHP code and the user names of the first 1000 UIDs, thank you. [Help] PHP collects webpage information
Need to collect
Http://bbs.zhanzhang.baidu.com/home.php? Mod = space & uid = *
User names with different UIDs
I'm not familiar with PHP and regular expressions. I just want to get the results. so I have to give the PHP code and the first 1000 UID usernames directly. thank you. Php
------ Solution --------------------
$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]);

In theory, uid is auto-incrementing. The first 1000 are 1-1000. change the number yourself.
------ Solution --------------------
$ Url = 'http: // bbs.zhanzhang.baidu.com/home.php? Mod = space & uid = ';

$ Res = array ();
$ Uid = 1;
While (count ($ res) <20) {// obtain the first 20 items and modify them as needed
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 );
Result: (the join key is UID and the value is the user name)

Array
(
[1] => sitemapbbs
[7] => _
[8] => sitemapTest2
[9] => sitemapTest
[10] => sitemapTest32
[13] => sitemapTest3
[14] => kkkksuper
[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
)

------ Solution --------------------
Same as above, but the file_get_contents method is sometimes too slow and curl can be used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.