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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 5495|回复: 7

[其他] 继续求助--登录求助

[复制链接]
发表于 2013-9-17 23:29:53 | 显示全部楼层 |阅读模式
带验证码登陆问题,先前发过一贴,由于存在一些问题,现在好了,因此再次发帖
我的思路是首先访问登陆页面,取得cookie,然后带着这个cookie再去访问验证码的页面,取得验证码图像显示在界面上,
然后用户自己手动输入,然后再继续带着这个cookie(带着验证码的图像的页面的cookie也试过)post登陆,一直
提示“本次请求并未返回任何数据”,不知何原因,小弟刚刚接触这个,还请给位帮忙看看是不是哪里弄错了,@站长苏飞
下面附上我的关键代码和工程文件
下面是获取验证码代码
  1.          string code_cookie;//保存cookie
  2.          
  3.         private void DOCaiJi_88city(object obj)
  4.         {
  5.             HttpHelper http = new HttpHelper();
  6.             HttpItem item = new HttpItem()
  7.             {
  8.                 URL = "http://xxxx.com/appg/login.php",//URL     必需项   
  9.                 Method = "get",//URL     可选项 默认为Get   
  10.                 IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写   
  11.                 Cookie = "",//字符串Cookie     可选项   
  12.                 Referer = "",//来源URL     可选项   
  13.                 Postdata = "",//Post数据     可选项GET时不需要写   
  14.                 Timeout = 100000,//连接超时时间     可选项默认为100000   
  15.                 ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000   
  16.                 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值   
  17.                 ContentType = "text/html",//返回类型    可选项有默认值   
  18.                 Allowautoredirect = false,//是否根据301跳转     可选项   
  19.             };
  20.             HttpResult result = http.GetHtml(item);
  21.             
  22.             code_cookie = result.Cookie;
  23.             item.URL = "http://g818city.com/appg/draw_gd.php";
  24.             item.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
  25.             item.Encoding = null;
  26.             item.ResultType = ResultType.Byte;
  27.             result = http.GetHtml(item);
  28.            
  29.             pictureBox1.Image = byteArrayToImage(result.ResultByte);

  30.             this.BeginInvoke(new MethodInvoker(delegate()
  31.             {
  32.                 this.button4.Enabled = true;
  33.             }));
  34.         }
复制代码
下面是post登陆的代码

  1.         private Image byteArrayToImage(byte[] Bytes)
  2.         {
  3.             MemoryStream ms = new MemoryStream(Bytes);
  4.             Image outputImg = Image.FromStream(ms);
  5.             return outputImg;
  6.         }

  7.         private void button7_Click(object sender, EventArgs e)
  8.         {
  9.             HttpHelper http = new HttpHelper();
  10.             string fr_gdcode = textBox1.Text.Trim();
  11.             HttpItem item = new HttpItem()
  12.             {
  13.                 URL = "http://xxx.com/appg/login.php?",//URL     必需项   
  14.                 Method = "post",//URL     可选项 默认为Get      
  15.                 Referer = "http://g818city.com/appg/login.php?lang=",//来源URL     可选项   
  16.                 Postdata = "fr_username=hu2828&fr_password=huqiliang131&fr_gdcode=" + fr_gdcode + "&language=simplified&fr_language=simplified&fr_companycode=a2700&fr_querycheck=http%3A%2F%2Fg818city.com%2Fappg%2Flogin.php",//Post数据     可选项GET时不需要写   
  17.                 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值   
  18.                 ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值   
  19.             };
  20.             
  21.             code_cookie = code_cookie.Replace("path=/,", "").Replace(";path=/", "");
  22.             item.Cookie = code_cookie;
  23.             HttpResult result = http.GetHtml(item);
  24.             string html2 = result.Html;

  25.             item.URL = "http://g818city.com/appg/login.php?";
  26.             item.Cookie = result.Cookie;
  27.             result = http.GetHtml(item);
  28.             string  html = result.Html;

  29.             StreamWriter sw = new StreamWriter("data.txt", true, Encoding.GetEncoding("gb2312"));
  30.             sw.WriteLine(html2+html + code_cookie);
  31.             sw.Close();
  32.             MessageBox.Show("完成!");
  33.         }
复制代码

ylc.rar

277.65 KB, 下载次数: 206, 下载积分: 金钱 -1

工程文件



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-9-18 07:39:43 | 显示全部楼层
我这边用了你发的账户全部是账户密码不对,从来没有登录成功过一次,你先解决下这个问题吧。想想会不会绑定IP或者还有什么别的限制了。
发表于 2013-9-18 08:44:42 | 显示全部楼层
[code=csharp]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;


using System.Net;
using System.IO;


using System.Text.RegularExpressions;


namespace GETBDTieBa
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


        }

        private void button4_Click(object sender, EventArgs e)
        {
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://xxx.com/appg/draw_gd.php",//URL     必需项   
                ResultType = ResultType.Byte
            };
            HttpResult result = http.GetHtml(item);
            code_cookie = result.Cookie;
            pictureBox1.Image = byteArrayToImage(result.ResultByte);

        }
        string code_cookie;
        private Image byteArrayToImage(byte[] Bytes)
        {
            MemoryStream ms = new MemoryStream(Bytes);
            Image outputImg = Image.FromStream(ms);
            return outputImg;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            HttpHelper http = new HttpHelper();
            string fr_gdcode = textBox1.Text.Trim();

            HttpItem item = new HttpItem()
            {
                URL = "http://xxx.com/appg/login.php",//URL     必需项   
                Method = "post",//URL     可选项 默认为Get      
                Referer = "http://xxx.com/appg/login.php",//来源URL     可选项   
                Postdata = "fr_username=hu2828&fr_password=huqiliang131&fr_gdcode=" + fr_gdcode + "&language=simplified&fr_language=simplified&fr_companycode=a2700&fr_querycheck=http%3A%2F%2Fg818city.com%2Fappg%2Flogin.php",//Post数据     可选项GET时不需要写   
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值  
                Cookie = code_cookie.Replace("path=/,", "").Replace("path=/", "")
            };

            HttpResult result = http.GetHtml(item);
            //这里要再次New一个,否则最少也应该修改一下Method,要不然还是继承上面的Post方式
            item = new HttpItem()
            {
                URL = "http://g818city.com/appg/system.php",//URL     必需项   
                Method = "get",//URL     可选项 默认为Get      
                Referer = "http://g818city.com/appg/login.php",//来源URL     可选项   
                Cookie = result.Cookie.Replace("path=/,", "").Replace("path=/", "")
            };
            result = http.GetHtml(item);
            string html = result.Html;

        }

    }
}
[/code]


最后取到的结果是这个
[code=html]<html>
<head>
<link rel="shortcut icon" href="images/favicon.ico">
<title>88娱乐城</title>
<style>
body
{
background-image: url(images/login_bg.jpg);
}

</style>
</head>
<frameset cols="*,998,*"  framespacing="0" frameborder="0"  >
  <frame src="bg.php" name="topFrame" id="topFrame" frameborder="0" scrolling="No" noresize>
<frameset rows="137,*" cols="*" framespacing="0" frameborder="0" >
  <frame src="header.php?" name="topFrame" id="topFrame" frameborder="0" scrolling="No" noresize>
   <frame src="betting-frame.php" name="mainFrame" id="mainFrame" scrolling="No" noresize>
</frameset>
  <frame src="bg.php" name="topFrame" id="topFrame" frameborder="0" scrolling="No" noresize>
</frameset>
<noframes>
<body></body>
</noframes>
</html>[/code]
就是一个frame 这应该是算成功了吧。
下面就是单独访问里面的页面了,这个你自己处理吧
带的都是登录成功之后的Cookie就行


发表于 2013-9-18 08:45:06 | 显示全部楼层
你的帖子标题写的太简单了,帮你加了一些
 楼主| 发表于 2013-9-18 08:47:08 | 显示全部楼层
站长苏飞 发表于 2013-9-18 08:44
最后取到的结果是这个

就是一个frame 这应该是算成功了吧。

谢谢站长了,又是站长一次次耐心的帮助,我这就看看啊
发表于 2013-9-18 09:05:31 | 显示全部楼层
wxfy2011 发表于 2013-9-18 08:47
谢谢站长了,又是站长一次次耐心的帮助,我这就看看啊

看吧,解决了回复下
 楼主| 发表于 2013-9-18 09:11:21 | 显示全部楼层
站长苏飞 发表于 2013-9-18 09:05
看吧,解决了回复下

可以了,登陆成功了,谢谢站长了
发表于 2013-9-18 09:14:12 | 显示全部楼层
wxfy2011 发表于 2013-9-18 09:11
可以了,登陆成功了,谢谢站长了

那就好,我结帖子了
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-14 05:52

© 2014-2021

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