Sina Technology Article collection code

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn about the applicable code of ThinkPhp in one-click collection of Sina Technology articles.
/* Collect Sina Technology articles */
Public function sina_tech (){
/* Need caull page num */
$ Page_num = intval ($ _ POST ['get _ post_page_num ']);
If (empty ($ page_num) $ page_num = 1;
/* First count */
$ Post_count_a = M ('post')-> count ();
/* For cull */
For ($ page = 1; $ page <= $ page_num; $ page ++ ){

$ Fullpage = CurlGetPage ('HTTP: // roll.tech.sina.com.cn/s/channel.php? Ch = 05 # col = 30 & spec = & type = & ch = 05 & k = & offset_page = 0 & offset_num = 0 & num = 5 & asc = & page = '. $ page );

Preg_match_all ('/ \ S + (. *) \ s + <\/p>/Us ', $ fullpage, $ match );
$ Fullpage = iconv ("GB2312", "UTF-8", $ match [1] [0]); // echo $ data1; die;

Preg_match_all ('/
  • (. *) <\/Li>/isU ', $ fullpage, $ in_li_tags );
    Foreach (array_unique ($ in_li_tags [1]) as $ row ){
    /* TITLE */
    Preg_match_all ('/(. *) <\/a>/', $ row, $ title );
    $ Title = $ title [1] [0];
    /* LINK */
    Preg_match_all ('/href = "([^"] *) "/', $ row, $ link );
    $ Link = $ link [1] [0];
    /* DATE */
    Preg_match_all ('/(. *) <\/span>/I', $ row, $ date );
    $ Date = date ("Y-", time (). $ date [1] [0]. ': 00 ';
    // Echo $ title. ''. $ link.''. $ date .'
    ';

    /* Going the post page */
    $ Fullpage_post = CurlGetPage ($ link );
    /* Fix tags */
    $ Fullpage_post = preg_replace ('/

    (. *) <\/P>/isU ',' $ {1} ', $ fullpage_post );
    $ Fullpage_post = preg_replace ('/

    (. *) <\/P>/'','', $ fullpage_post );
    // Echo htmlspecialchars ($ fullpage_post); die;

    /* Post content */
    Preg_match_all ('/ \ S + (. *) \ s + <\/p>/Us ', $ fullpage_post, $ post_content );
    /* Del a tags */
    $ Post_content = preg_replace ("/] *> (. *) <\/a>/isU", '$ {1}', $ post_content [1] [0]);
    // Echo ''. $ title.''. $ url .'
    '. $ Date .'
    '. $ PostCon .'

    ';

    /* Save to db */
    $ Post_title_count = M ('post')-> where ("title = '$ title'")-> count ();
    If ($ post_title_count = 0 ){
    $ DataMySql ["title"] = $ title;
    $ DataMySql ["content"] = $ post_content;
    $ DataMySql ["datetime"] = $ date;
    M ('post')-> add ($ dataMySql );
    }
    }
    }
    /* Last count */
    $ Post_count_ B = M ('post')-> count ();
    $ Post_add_num = $ post_count_ B-$ post_count_a;
    /* CALLBACK */
    If ($ post_count_a ==$ post_count_ B ){
    Echo '{"success": 1, "msg": "no change in the number of articles "}';
    } Else {
    Echo '{"success": 1, "msg": "collection successful'. $ post_add_num. 'Article "}';
    }
    }

    AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

  • 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.