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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 7683|回复: 11

[其他] 用httphelper登录163不成功,请帮我看下哪里错了。谢谢。

[复制链接]
发表于 2013-1-22 11:58:00 | 显示全部楼层 |阅读模式
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.HtmlControls;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using DotNet.Utilities;
  12. using System.Text;

  13. namespace WebApplication2
  14. {
  15.     public partial class _Default : System.Web.UI.Page
  16.     {
  17.         protected void Page_Load(object sender, EventArgs e)
  18.         {

  19.         }

  20.         public static string URLDecode(string text)
  21.         {
  22.             return HttpUtility.UrlDecode(text, Encoding.Default);
  23.         }
  24.         public static string URLEncode(string text)
  25.         {
  26.             return HttpUtility.UrlEncode(text, Encoding.Default);
  27.         }

  28.         protected void Button1_Click(object sender, EventArgs e)
  29.         {
  30.             HttpItem item = new HttpItem()
  31.             {
  32.                 URL = "https://reg.163.com/logins.jsp?url=&product=urs&savelogin=&outfoxer=&domains=" +
  33.                 "&syscheckcode=bf304d663b8437558a9c075beb2f2375afe88a57&username="
  34.                 + URLEncode("abc@163.com") + "&password="
  35.                 + URLEncode("abc") + "&Submit=",
  36.                 Referer = "https://reg.163.com/logins.jsp"
  37.             };

  38.             HttpHelper http = new HttpHelper();

  39.             string html = http.GetHtml(item);

  40.             string cookie = item.Cookie;

  41.             //TextBox1.Text = "cookie:" + cookie + "\r\n\r\n";

  42.             //使用Cookie转到主页
  43.             item.URL = "http://reg.163.com/Main.jsp";

  44.             TextBox1.Text += http.GetHtml(item);
  45.         }

  46.         protected void TextBox1_TextChanged(object sender, EventArgs e)
  47.         {

  48.         }
  49.     }
  50. }
复制代码


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-1-22 12:16:17 | 显示全部楼层
用我的代码可以登录,直接放在你Button事件下就行了
[code=csharp] //get方式

            HttpItem item = new HttpItem()
            {
                URL = "https://reg.163.com/logins.jsp?url=&product=&savelogin=&outfoxer=&domains=" +
                "&syscheckcode=034715eb7e1f16cd332e41f95e3303204ceadd7e&username="
                + "账户" + "&password="
                + "密码" + "&Submit=",
                Referer = "https://reg.163.com/logins.jsp"
            };
            HttpHelper http = new HttpHelper();
            string html = http.GetHtml(item);
            string cookie = item.Cookie;

            TextBox1.Text = "cookie:" + cookie + "\r\n\r\n";

            //使用Cookie转到主页http://reg.163.com/Main.jsp
            item.URL = "http://reg.163.com/Main.jsp";
            TextBox1.Text += http.GetHtml(item);[/code]
 楼主| 发表于 2013-1-22 12:33:32 | 显示全部楼层
本帖最后由 unranked 于 2013-1-22 12:34 编辑
admin 发表于 2013-1-22 12:16
用我的代码可以登录,直接放在你Button事件下就行了

是firebug取到的postdata不对啊。
为什么我这边用自己取的postdata一直都不对呢。
我firefox是英文版18.0.1 firebug是1.11.1
会有什么问题吗
 楼主| 发表于 2013-1-22 12:49:46 | 显示全部楼层
admin 发表于 2013-1-22 12:16
用我的代码可以登录,直接放在你Button事件下就行了

我把
TextBox1.Text += http.GetHtml(item);
放在
item.URL = "http://reg.163.com/Main.jsp";
的前面,显示的登录信息就是对的,提示说正在登录。
要是放到后面,就提示请重新登录。
发表于 2013-1-22 13:06:17 | 显示全部楼层
用我的代码可以了吧应该,
 楼主| 发表于 2013-1-22 13:11:29 | 显示全部楼层
admin 发表于 2013-1-22 13:06
用我的代码可以了吧应该,

可以的。
另外问个问题。
我另一个函数里有
System.Net.CookieCollection cookies
这个参数,
怎么将httphelper里的cookie赋值给他呢
cookies = item.Cookie;
提示类型不对。item.Cookie好像是string类型的。
问题太弱了点。
发表于 2013-1-22 13:25:31 | 显示全部楼层
item里不是有CookieCollection 吗?直接使用CookieCollection
 楼主| 发表于 2013-1-22 15:03:09 | 显示全部楼层
admin 发表于 2013-1-22 13:25
item里不是有CookieCollection 吗?直接使用CookieCollection

嗯。
为什么我把
TextBox1.Text = http.GetHtml(item);
放在
item.URL = "http://reg.163.com/Main.jsp";
之后就显示说请重新登录呢
发表于 2013-1-22 15:04:37 | 显示全部楼层
unranked 发表于 2013-1-22 15:03
嗯。
为什么我把
TextBox1.Text = http.GetHtml(item);

http.GetHtml(item) 是根据URL获取HTML代码的,那有先获取代码才传入URL的,你不指定URL肯定不会对啊
 楼主| 发表于 2013-1-22 16:10:56 | 显示全部楼层
admin 发表于 2013-1-22 15:04
http.GetHtml(item) 是根据URL获取HTML代码的,那有先获取代码才传入URL的,你不指定URL肯定不会对啊

TextBox1.Text = http.GetHtml(item);
放在
item.URL = "http://reg.163.com/Main.jsp";
的前面,得到的是正在跳转。。对吧。

要是想得到跳转以后的html
不是要放在后面让他显示html吗
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-3-29 01:55

© 2014-2021

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