① php模拟登陆QQ空间
PHP代码:
<php
$qq = "100000"; //qq号码
$pwd = "123456"; //密码
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://211.139.167.71/waptest/TWF/qqportal/rela/updateuserinfo.jsp");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //这行是设定curl是否跟随header发送的location, 重要
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, "Connection", "Keep-Alive");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "qq=".$qq."&pwd=".$pwd."&FromWhere=register");
$return = curl_exec($ch);
curl_close($ch);
echo strstr($return, "postfield") ? "登录失败" : "登录成功";
?>
注:1、需curl模块支持,2、登陆后,你的好友将会看到你在线 3、不知道如何下线。
其他语言的实现类似,有兴趣的朋友可以自己动手开发一下。
这个你试试
② php curl登陆和获取内容类,请各位高手看怎么使用
由于每个网站的信息不一样,没有通用的curl的。等看你的具体需求,若你要模拟登录可以看下snoopy,一个基于curl的类,抓取信息可以用querylist
③ php curl 无法实现模拟登陆
<?php
$discuz_url = 'http://127.0.0.1/discuz/';//论坛地址
$login_url = $discuz_url .'logging.php?action=login';//登录页地址
$post_fields = array();
//以下两项不需要修改
$post_fields['loginfield'] = 'username';
$post_fields['loginsubmit'] = 'true';
//用户名和密码,必须填写
$post_fields['username'] = 'tianxin';
$post_fields['password'] = '111111';
//安全提问
$post_fields['questionid'] = 0;
$post_fields['answer'] = '';
//@todo验证码
$post_fields['seccodeverify'] = '';
//获取表单FORMHASH
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}
//POST数据,获取COOKIE,cookie文件放在网站的temp目录下
$cookie_file = tempnam('./temp','cookie');
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
//取到了关键的cookie文件就可以带着cookie文件去模拟发帖,fid为论坛的栏目ID
$send_url = $discuz_url."post.php?action=newthread&fid=2";
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
//这里的hash码和登陆窗口的hash码的正则不太一样,这里的hidden多了一个id属性
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*id="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}
$post_data = array();
//帖子标题
$post_data['subject'] = 'test2';
//帖子内容
$post_data['message'] = 'test2';
$post_data['topicsubmit'] = "yes";
$post_data['extra'] = '';
//帖子标签
$post_data['tags'] = 'test';
//帖子的hash码,这个非常关键!假如缺少这个hash码,discuz会警告你来路的页面不正确
$post_data['formhash']=$formhash;
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_REFERER, $send_url); //伪装REFERER
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$contents = curl_exec($ch);
curl_close($ch);
//清理cookie文件
unlink($cookie_file);
?>
④ php Snoopy模拟不成功.CURL模拟成功.这是为什么
您好,希望以下回答能帮助您
请使用SNOOPY,你网络一下就有下载地址了他是对CURL的封装,大网站很多都用这个
如您还有疑问可继续追问。
⑤ 请问PHP模拟登录后怎么保持session总是不能成功保持session到目标站的其他页面
请问楼主 最后怎么解决的此问题 ,求公布答案, 我也是碰到这个问题了,能模拟登录成功并且获取到cookie保存,然后总是返回登录成功后 第一个看到的页面,再获取其他页面就不行了,目标服务器也是和你的问题一样,通过session 来判断
⑥ php curl 抓取美团网页次数过多,同一个ip访问被限制怎么办如何解决
模拟成搜索引擎来采集,我采集新闻的时候遇到过这个问题 可以到我的blog去查看
搜索采集
⑦ php伪造ip获取网页内容,求高手
伪造IP是不可能的,HTTP协议是机遇TCP,你发送GET命令过去必须留有准确的IP地址,否则对方无法把结果发给你,你与服务器xxx.xxx.xx的通讯相当于写信,你匿名写信只能攻击,要获取返回的东西必须提交真实的地址。
无论使用CURL还是别的方法,都要受前面的基本规则限制。
编程上已经没有办法可走了,你可以考虑使用代理,通过代理服务器去获取数据,查封就换个代理服务器。不过现在代理服务器是很难找的。
⑧ 用PHP抓取一个页面,但是这个页面需要登录才能显示,怎么抓取呢需要代码
可以使用Snoopy.class.php这个类模拟登陆,然后再抓取你想要抓取的那个页面。
⑨ Snoopy采集,thinkphp使用snoopy采集数据
呵呵。这种情况,看看是不是程序那里有错误了吧。
一般情况不会出现这么大内存需求的。
另外,如果你开启的是snoopy的多线程测试,可以考虑把线程数量减少。
还有就是循环执行时间,也可以适当减少再试试。