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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 3067|回复: 2

[求助] 求助苏飞百度推广后台账号登陆问题:使用webbrowser登陆后获取cookie后,提交查询失败

[复制链接]
发表于 2014-7-3 11:50:51 | 显示全部楼层 |阅读模式
本帖最后由 tylrr 于 2014-7-3 15:30 编辑

我使用webbrowser打开百度的推广后台登陆页面后,手动输入账号登陆,然后获取了登陆后的cookie,然后把cookie值传递给httpHelper,提交post请求去查询。
但是不知道什么原因,老是出错,提示:"Unable to connect to the remote server"        。
网络是正常的,请问是哪里出错呢?  谢谢指点


首先使用webbrowser控件加载登陆页面,手动输入账号和密码登陆后,获取到登陆后的cookie。然后把cookie赋值到httphelper进行查询。
private void test1()
        {
            string tk = "";
            string tk2 = "";
            string mycookie = "";
            string pattern = "(?<=cas__st__=).*?(?=;)";
            MatchCollection collection = Regex.Matches(MainCookie.Cookie, pattern);
            foreach (Match match in collection)
            {
                tk = match.ToString();   //获取token1
            }
            pattern = ".{10}";
            collection = Regex.Matches(tk, pattern);
            foreach (Match match in collection)
            {
                tk2 = match.ToString();  //获取token2
            }

            
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://fengchao.baidu.com/nirvana/request.ajax?path=GET/kr/word&reqid=lig0s75s0m",//URL     必需项   
                Method = "post",//URL     可选项 默认为Get   
                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写   
                Cookie = MainCookie.Cookie,  //获取到登陆后的cookie
                Referer = "http://fengchao.baidu.com/nirvana/main.html?userid=5599168&t=1404351595401#/manage/plan",//来源URL     可选项   
                Postdata = "eventId=&path=GET%2Fkr%2Fword&userid=5599168&token=" + tk + "&#182;ms={\"logid\":982890698,\"planid\":0,\"unitid\":0,\"entry\":\"kr_tools\",\"query\":\"test\",\"regions\":\"\",\"rgfilter\":1,\"device\":0,\"querytype\":1,\"querySessions\":[\"test\",\"心理\",\"测试\"]}",//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 = "application/x-www-form-urlencoded; charset=utf-8",//返回类型    可选项有默认值   
                Allowautoredirect = true,//是否根据301跳转     可选项   
                ResultType = ResultType.String
            };
            HttpResult result = http.GetHtml(item);   //根据抓包信息进行第1次查询
            mycookie = result.Cookie;
            Debug.Write("cookie:"+MainCookie.Cookie+"\r\n");

                HttpItem item2 = new HttpItem();
                item2.URL = "http://fclog.baidu.com/nirvana/log/fclogimg.gif";//URL     必需项   
                item2.Method = "post";//URL     可选项 默认为Get   
                item2.IsToLower = false;//得到的HTML代码是否转成小写     可选项默认转小写
                item2.Cookie = mycookie;//字符串Cookie     可选项
                item2.Referer = "http://fengchao.baidu.com/nirvana/main.html?userid=5599168&t=1404351595401";//来源URL     可选项   
                item2.Postdata = "userid=5599168&optid=5599168&ulevelid=10101&token=" + tk2 + "&exp=undefined&path=%252Fmanage%252Fplan&fn=query&logid=982890698&entry=kr_tools&krType=1&query=test&#174;ion=&rgfilter=1&isResearch=1&krCol=word%252Ctotal_weight%252Cpv%252Ckwc&lastTarget=queryResponse";//Post数据     可选项GET时不需要写   
                item2.Timeout = 100000;//连接超时时间     可选项默认为100000   
                item2.ReadWriteTimeout = 30000;//写入Post数据超时时间     可选项默认为30000   
                item2.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";//用户的浏览器类型,版本,操作系统     可选项有默认值   
                item2.ContentType = "application/x-www-form-urlencoded; charset=utf-8";//返回类型    可选项有默认值   
                item2.Allowautoredirect = true;//是否根据301跳转     可选项   
                item2.ResultType = ResultType.String;
            
            result = http.GetHtml(item2);     //根据抓包信息进行第2次查询
            string html = result.Html;
            MessageBox.Show(html);
            mycookie = result.Cookie;


        }




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-7-3 12:51:52 | 显示全部楼层
这个我没写过,你可以提供下包看看。建议你公开一下,让更多的帮助你,如果有账户密码,可以写成替换字符
发表于 2014-7-4 16:10:20 | 显示全部楼层
mack
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-29 17:41

© 2014-2021

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