• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

爬人人网好友遇到的模拟登陆问题

php 搞代码 4年前 (2022-01-23) 22次浏览 已收录 0个评论
文章目录[隐藏]

我用网上别人的模拟登陆代码
<?php
$username=”[email protected]”;//$_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(‘./cookie’,’renren’);
$ch=&getCurl($cookie_jar,”POST”,”http://www.renren.com/ajaxLogin/login&#8221;);
curl_setopt($ch,CURLOPT_POSTFIELDS,’email=’.urlencode($renren_username).’&password=’.urlencode($renren_password).’&origURL=http%3A%2F%2Fwww.renren.com%2FHome&domain=renren.com&key_id=1&captcha_type=web_login&_rtk=90ae5f12′);
$str=&sendAndResult($ch);
$ch = &getCurl($cookie_jar,”GET”,”http://www.renren.com/123456&#8243;);
$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;
}
我原以为模拟登陆后,就可以任意登陆我的人人主页或者查看好友,但当我
$URL=”http://本文来源gaodai#ma#com搞*!代#%^码$网!搞代gaodaima码friend.renren.com/GetFriendList.do?curpage=0&id=382556764″;
$fcontents=file_get_contents($URL);
echo”$fcontents”;
又被弹回登陆界面了,请问有什么办法可以让我一直保持连接。
谢谢!

回复讨论(解决方案)

简单的 file_get_contents 不会传递 cookie
而既然是需要登陆的,那么 cookie 总是要传递的
继续使用的的 getCurl 呀

简单的 file_get_contents 不会传递 cookie
而既然是需要登陆的,那么 cookie 总是要传递的
继续使用的的 getCurl 呀
你意思是只要登陆一个页面就得还发一次cookie吗?
我以为和浏览器一样,我发了一次,后面的就不用发了。。。新手求拍。。

是的,和浏览器一样每次都要发送 cookie

是的,和浏览器一样每次都要发送 cookie
行,谢谢,本来想偷个懒 ,那每次发就每次发吧,反正写到函数里的。分给你了

是的,和浏览器一样每次都要发送 cookie
行,谢谢,本来想偷个懒 ,那每次发就每次发吧,反正写到函数里的。分给你了
谢谢版主,我人人网的写完了,现在要做微博的,我要怎么改啊
我觉得只需要该curl_setopt($ch,CURLOPT_POSTFIELDS,’email=’.urlencode($renren_username).’&password=’.urlencode($renren_password).’&origURL=http%3A%2F%2Fwww.renren.com%2FHome&domain=renren.com&key_id=1&captcha_type=web_login&_rtk=90ae5f12′);
里面的第三个参数就行了,但新浪微博的要对应改成什么样呢。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:爬人人网好友遇到的模拟登陆问题

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址