Simulated login problems when crawling Renren's network friends

Source: Internet
Author: User
Simulated login problems encountered by crawling Renren's network friends I used simulated login code from someone else on the Internet
$ Username = "xxx@126.com"; // $ _ POST ["username"];

$ Password = "xxx"; // $ _ POST ["password"];

$ Message = "1"; // $ _ POST ["message"];

If ($ message! = ""){

UpdateRenren ($ message, $ username, $ password, 0 );

Echo $ message;

}

Function updateRenren ($ status, $ renren_username, $ renren_password, $ tried_times ){
If ($ tried_times> = 3 ){
Return false;
}

$ Cookie_jar = tempnam ('./cooker', 'renrenren ');
$ Ch = & getCurl ($ cookie_jar, "POST", "http://www.renren.com/ajaxLogin/login ");
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, 'Email = '. urlencode ($ renren_username ). '& password = '. urlencode ($ renren_password ). '& origURL = http % 3A % 2F % 2Fwww.renren.com % 2 FHome & domain = renren.com & key_id = 1 & captcha_type = web_login & _ rxns= 90ae5f12 ');
$ Str = & sendAndResult ($ ch );
$ Ch = & getCurl ($ cookie_jar, "GET", "http://www.renren.com/123456 ");
$ Ret = & sendAndResult ($ ch );
}

Function & getCurl ($ jar, $ method, $ url ){
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ jar );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ jar );
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, TRUE );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE );
Curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv: 1.9.2.8) Gecko/20100722 Firefox/3.6.8 ");
// Curl_setopt ($ ch, CURLOPT_VERBOSE, true );
If ($ method = "POST "){
Curl_setopt ($ ch, CURLOPT_POST, TRUE );
} Else {
Curl_setopt ($ ch, CURLOPT_POST, FALSE );
}
Return $ ch;
}

Function & sendAndResult (& $ ch ){
$ Str = curl_exec ($ ch );
Curl_close ($ ch );
Unset ($ ch );
Echo $ str;
Return $ str;
}
I thought that after simulated login, I could log on to my Renren homepage or view my friends, but when I
$ URL = "http://friend.renren.com/GetFriendList.do? Curpage = 0 & id = 382556764 ";
$ Fcontents = file_get_contents ($ URL );
Echo "$ fcontents ";
The login page is popped up again. Is there any way I can keep connected.
Thank you!


Reply to discussion (solution)

Simple file_get_contents does not pass cookies
Since login is required, cookies are always transmitted.
Continue to use the getCurl.

Simple file_get_contents does not pass cookies
Since login is required, cookies are always transmitted.
Continue to use the getCurl.
Do you mean you have to send a cookie once after logging on to a page?
I thought I sent it once like a browser, so I don't need to send it later... For beginners ..

Yes. like the browser, the cookie is sent every time.

Yes. like the browser, the cookie is sent every time.
All right, thank you. I was trying to steal a lazy job. let's send it each time. it's written to the function anyway. Assigned to you


Yes. like the browser, the cookie is sent every time.
All right, thank you. I was trying to steal a lazy job. let's send it each time. it's written to the function anyway. Assigned to you
Thank you, moderator. I have finished my work on Renren.com. now I want to make a microblog. how can I change it?
I think only the curl_setopt ($ ch, CURLOPT_POSTFIELDS, 'Email = '. urlencode ($ renren_username ). '& password = '. urlencode ($ renren_password ). '& origURL = http % 3A % 2F % 2Fwww.renren.com % 2 FHome & domain = renren.com & key_id = 1 & captcha_type = web_login & _ rxns= 90ae5f12 ');
The third parameter is enough, but what should I change from Sina Weibo.

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.