免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3108 | 回复: 6
打印 上一主题 下一主题

模拟登录网站总是不成功,怎么办? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-21 18:18 |只看该作者 |倒序浏览
本帖最后由 workingbeijing 于 2010-05-22 13:01 编辑

$target = "http://www.mysteel.com/user/login.ms";

# Define the login form data
$form_data="sUserName=coderjoy&sPassword=123456&url=http://www.mysteel.com/";

# Create the cURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target); // Define target site
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in stringcurl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // Tell cURL where to write cookies
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); // Tell cURL which cookies to send
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
# Execute the PHP/CURL session and echo the downloaded page
$page = curl_exec($ch);
echo $page;


curl_close($ch);

这种方法不能返回登录完的状态,其它网站可以,是不是因为这个login.ms?还有没有其它的方法。其它的网站用这个方法可以登录,只有这个不可以

论坛徽章:
0
2 [报告]
发表于 2010-05-22 08:14 |只看该作者
自己顶

论坛徽章:
0
3 [报告]
发表于 2010-05-22 13:30 |只看该作者
可以使用 Snoopy 来执行
这个网站的数据我经常用到的:wink:

论坛徽章:
0
4 [报告]
发表于 2010-05-22 14:02 |只看该作者
本帖最后由 workingbeijing 于 2010-05-22 14:08 编辑

<?php
include "lib/Snoopy.class.php";
$snoopy = new Snoopy;
$submit_url = "http://www.mysteel.com/user/login.ms";


$submit_vars["sUserName"] = "coderjoy"; //你的用户名
$submit_vars["sPassword"] = "123456"; //你的密码
$submit_vars['url'] = "http://www.mysteel.com/";
$snoopy->submit($submit_url,$submit_vars);
print $snoopy->results;

?>

论坛徽章:
0
5 [报告]
发表于 2010-05-22 14:16 |只看该作者
使用snopy这样写还是不行,还有没有其它的办法?

论坛徽章:
0
6 [报告]
发表于 2010-05-22 15:13 |只看该作者
wireshark截包后 post的地址不是你那个的。

  1. require("Snoopy.class.php");

  2. $snoopy = new Snoopy();

  3. $url = 'http://member1.mysteel.com/login.shtml';
  4. $form = array (
  5.         'userName'        =>        'coderjoy',
  6.         'password'        =>        '123456'
  7. );

  8. $rs = $snoopy->submit($url, $form);

  9. $snoopy->fetch('http://member1.mysteel.com/supply/index.shtml');

  10. $fp = fopen('mysteel.html', 'w');
  11. fwrite($fp, $snoopy->results);
  12. fclose($fp);
复制代码

论坛徽章:
0
7 [报告]
发表于 2010-05-22 15:17 |只看该作者
ok了,研究下

谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP