http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 9231|回复: 15

[其他] POST登陆网站

[复制链接]
发表于 2013-8-28 22:04:18 | 显示全部楼层 |阅读模式
我需要登陆www.0711.com这个网站,对于这个页面http://www.0711.com/viewpers.asp?pname=19930815 不登陆联系方式是看不到的
登陆http://www.0711.com/comp/login.asp通过firebug抓取到post参数为
logintype=comp&user=feifei20132&pwd=123456&Submit.x=0&Submit.y=0
我通过下面的代码就是不成功啊采集不到联系方式,Submit.x=0&Submit.y=0这两个参数页面源码也没有找到不知道是什么,我把post方法改成get参数写的url中也是不行,请大神帮忙解决啊
@站长苏飞
[code=csharp] HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.0711.com/comp/login.asp",//URL     必需项   
                Method = "post",//URL     可选项 默认为Get   
                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写   
                Cookie = "",//字符串Cookie     可选项   
                Referer = "",//来源URL     可选项   
                Postdata = "logintype=comp&user=feifei20132&pwd=123456&Submit.x=0&Submit.y=0",//Post数据     可选项GET时不需要写   
                Timeout = 100000,//连接超时时间     可选项默认为100000   
                ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000   
                UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值   
                ContentType = "text/html",//返回类型    可选项有默认值   
                Allowautoredirect = false,//是否根据301跳转     可选项   
                //CerPath = "d:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数   
                //Connectionlimit = 1024,//最大连接数     可选项 默认为1024   
                ProxyIp = "",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数   
                //ProxyPwd = "123456",//代理服务器密码     可选项   
                //ProxyUserName = "administrator",//代理服务器账户名     可选项   
            };
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            string cookie = result.Cookie;
        
            StreamWriter sw2 = new StreamWriter("1.html", true, Encoding.GetEncoding("gb2312"));
            sw2.WriteLine(html);
            sw2.Close();

            item.URL = "http://www.0711.com/viewpers.asp?pname=19930815";
            result = http.GetHtml(item);
            html = result.Html;

            sw2 = new StreamWriter("2.html", true, Encoding.GetEncoding("gb2312"));
            sw2.WriteLine( html);
            sw2.Close();
[/code]


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-8-28 22:11:14 | 显示全部楼层
模仿站长之前登陆网易邮箱的例子也不行
[code=csharp] HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.0711.com/comp/login.asp?logintype=comp&user=feifei20132&pwd=123456&Submit.x=33&Submit.y=7",//URL     必需项   
                Method = "get",//URL     可选项 默认为Get   
                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写   
                Cookie = "",//字符串Cookie     可选项   
                Referer = "",//来源URL     可选项   
                Postdata = "",//Post数据     可选项GET时不需要写   
                Timeout = 100000,//连接超时时间     可选项默认为100000   
                ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000   
                UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值   
                ContentType = "text/html",//返回类型    可选项有默认值   
                Allowautoredirect = false,//是否根据301跳转     可选项   
                //CerPath = "d:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数   
                //Connectionlimit = 1024,//最大连接数     可选项 默认为1024   
                ProxyIp = "",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数   
                //ProxyPwd = "123456",//代理服务器密码     可选项   
                //ProxyUserName = "administrator",//代理服务器账户名     可选项   
            };
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            string cookie = result.Cookie;
        
            StreamWriter sw2 = new StreamWriter("1.html", true, Encoding.GetEncoding("gb2312"));
            sw2.WriteLine(html);
            sw2.Close();

            item.URL = "http://www.0711.com/viewpers.asp?pname=19930815";
            result = http.GetHtml(item);
            html = result.Html;

            sw2 = new StreamWriter("2.html", true, Encoding.GetEncoding("gb2312"));
            sw2.WriteLine( html);
            sw2.Close();[/code]
发表于 2013-8-28 22:25:29 | 显示全部楼层
Content-Type        application/x-www-form-urlencoded
加上这个看看
 楼主| 发表于 2013-8-28 22:31:11 | 显示全部楼层
风清扬 发表于 2013-8-28 22:25
Content-Type        application/x-www-form-urlencoded
加上这个看看

还是不行,我把后面的换成下面了也不行
            item.URL = "http://www.0711.com/viewpers.asp?pname=19930815";
            item.Cookie = result.Cookie;
            item.Method = "get";
            result = http.GetHtml(item);
            html = result.Html;

 楼主| 发表于 2013-8-28 22:49:27 | 显示全部楼层
下面是抓包的数据
  1. 参数application/x-www-form-urlencoded
  2. Submit.x        49
  3. Submit.y        6
  4. logintype        comp
  5. pwd        123456
  6. user        feifei20132
  7. 源代码
  8. logintype=comp&user=feifei20132&pwd=123456&Submit.x=49&Submit.y=6

  9. Cache-Control        private
  10. Content-Length        137
  11. Content-Type        text/html
  12. Date        Wed, 28 Aug 2013 14:17:22 GMT
  13. Location        comp/default.asp
  14. Server        Microsoft-IIS/6.0
  15. X-Powered-By        ASP.NET
  16. 请求头信息原始头信息
  17. Accept        text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  18. Accept-Encoding        gzip, deflate
  19. Accept-Language        zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
  20. Connection        keep-alive
  21. Cookie        ASPSESSIONIDSCDSRSRR=HDKJNCICNPFGOBNDHHHPEEEJ; cck_lasttime=1377693985252; cck_count=0
  22. Host        www.0711.com
  23. Referer        http://www.0711.com/comp/login.asp
  24. User-Agent        Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20100101 Firefox/23.0
  25. 来自上传流的请求头信息
  26. Content-Length        65
  27. Content-Type        application/x-www-form-urlencoded
复制代码
发表于 2013-8-29 08:50:48 | 显示全部楼层
被楼主误导了,其实登录的时候是post给“http://www.0711.com/login.asp”而不是楼主写的“http://www.0711.com/comp/login.asp”,问题圆满解决
发表于 2013-8-29 08:56:10 | 显示全部楼层
[code=csharp] HttpHelper http = new HttpHelper();

            HttpItem item = new HttpItem()
           {
               URL = "http://www.0711.com/login.asp",//URL     必需项   
               Method = "post",//URL     可选项 默认为Get      
               Referer = "http://www.0711.com/comp/login.asp",//来源URL     可选项   
               Postdata = "logintype=comp&user=feifei20132&pwd=123456&Submit.x=46&Submit.y=13",//Post数据     可选项GET时不需要写   
               UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值   
               ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值     
           };

            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            item.URL = "http://www.0711.com/viewpers.asp?pname=19930815";
            item.Cookie = result.Cookie;
            result = http.GetHtml(item);
            html = result.Html;
[/code]
用这个可以登录成功
 楼主| 发表于 2013-8-29 11:13:15 | 显示全部楼层
站长苏飞 发表于 2013-8-29 08:56
用这个可以登录成功

不是那个地址的问题,之前也换过,换成站长的代码
也不行,返回 “ 无法在提交请求后执行此操作”


 楼主| 发表于 2013-8-29 11:13:38 | 显示全部楼层
太阳雨 发表于 2013-8-29 08:50
被楼主误导了,其实登录的时候是post给“http://www.0711.com/login.asp”而不是楼主写的“http://www.0711 ...

不是那个地址的问题,之前也换过,返回 “ 无法在提交请求后执行此操作”
发表于 2013-8-29 11:22:07 | 显示全部楼层
发你的代码过来吧,我测试可以正确获得联系方式
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-2 00:02

© 2014-2021

快速回复 返回顶部 返回列表