Sina News thieves

Source: Internet
Author: User
Tags ereg mysql host
Sina News stealing 1.html headmetahttp-equivRefreshcontent60METAHTTP-EQUIVPragmaCONTENTno-cachemetahttp-equivContent-Typecontenttexthtml; charset ?????? Title Sina _ news capture program titleheadbodycenterimgalt Sina News thieves s Sina News thieves 1.






Sina _ news capture program




$ Host = "127.0.0.1"; // MYSQL host name
$ Namesql = "???? "; // MYSQL User name
$ Passsql = "???? "; // MYSQL password
$ Lib = "news"; // database name
$ Table = "news"; // database table name
$ Filename = "http://news.sina.com.cn/news1000/index.shtml"; // capture the news page
$ Keytop = "start of news"; // keyword of start of news
$ Keybottom = "end of news"; // keyword of end of news

$ Conn = mysql_connect ($ host, $ namesql, $ passsql );
Mysql_select_db ($ lib, $ conn );

$ Fp = fopen ($ filename, "r", 1 );
$ Flag = 0; $ add = ""; $ found = 0; $ end = 0; $ I = 0; $ temp [4] = "";
While (! $ End = 1 ){
While (! $ Flag = 1 ){
$ Word = fgetc ($ fp );
$ Add = $ add. $ word;
If ($ word = '<' and strlen ($ add) = 1) {$ flag = 0 ;}
If ($ word = '<' and strlen ($ add )! = 1) {$ flag = 1; $ add = substr ($ add, 0, strlen ($ add)-1 );}
If ($ word = '>') {$ flag = 1 ;}}

If (strchr ($ add, $ keytop) {$ found = 1 ;}
If (strchr ($ add, $ keybottom) {$ found = 0; $ end = 1 ;}
If (strchr ($ add, '<') = True and strchr ($ add, 'href ') = True) or strchr ($ add,' <') = False) and $ found = 1) {$ text [$ I] = $ add; $ I ++ ;}
If ($ word = '<' and $ flag = 1) {$ add = $ word; $ flag = 0;} else {$ add = ""; $ flag = 0 ;}}
Fclose ($ fp );

For ($ I = 1; $ I $ Temp [1] = $ text [$ I + 1]; $ temp [2] = $ text [$ I + 2]; $ temp [3] = $ text [$ I + 3]; $ temp [4] = $ text [$ I + 4];
$ Ins = "select * from $ table where TITLE = '$ temp [3]'";
$ List = mysql_query ($ ins, $ conn );
@ $ Count = mysql_num_rows ($ list );
If ($ count = 0 ){
$ Ins = "insert into $ table (TYPE, URL, TITLE, DATE) values ('$ temp [1]', '$ temp [2]', '$ temp [3]', '$ temp [4]') ";
$ List = mysql_query ($ ins, $ conn );}}
Mysql_close ($ conn );
?>






2. $ Handle = fopen ("http://news.sina.com.cn/news1000/", "r ");
$ Sign = 0;
While (! Feof ($ handle ))
{
$ Message = fgets ($ handle, 512 );
If ($ sign = 1)
{
Print ("$ message ");
}
If (ereg ("news start", $ message, $ result ))
{
$ Sign = 1;
}
Else if (ereg ("end of news", $ message, $ result ))
{
$ Sign = 0;
}
}
Fclose ($ handle );
?>

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.