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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 4914|回复: 3

[HttpHelper] post登录主页有跳转不知道搞啊

[复制链接]
发表于 2017-9-23 11:28:52 | 显示全部楼层 |阅读模式
[C#] 纯文本查看 复制代码
 string data = "loginUserName=" + zh + "&loginUserPsd=" + pwd;
            string url = "http://hy.3yx.com/login_submit";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.Host = "hy.3yx.com";
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
            request.Headers.Add("Accept-Encoding", "gzip, deflate");
            request.Referer = "http://hy.3yx.com/login?s_from=6A7FFE81F3094D48EB40CF95FF82516578540F4A5BD7BC84";
            request.CookieContainer = cc;
            request.ContentType = "application/x-www-form-urlencoded";

           //request.ServicePoint.Expect100Continue = true;
            request.AllowAutoRedirect = true;
            
            request.MaximumAutomaticRedirections = 1;
            string newUrl = request.Headers["Location"];//获取重定向的网址
           // request.KeepAlive = true;
            request.ContentLength = System.Text.Encoding.UTF8.GetBytes(data).Length;
            request.Timeout = 20000;
            System.IO.Stream smWrite = request.GetRequestStream();
            smWrite.Write(System.Text.Encoding.UTF8.GetBytes(data), 0, System.Text.Encoding.UTF8.GetBytes(data).Length);
            smWrite.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
          
            WebHeaderCollection Headers =  response.Headers;
            //Stream myResponseStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("GBK"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            //retString = DlbZy("http://www.3yx.com", ref cc);
            return retString;

提交可以成功返回
[HTML] 纯文本查看 复制代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xHTML1/DTD/xHTML1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xHTML">
  <head>
    <title>正在跳转...</title>
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
  </head>
  <body>
  <script type="text/javascript">
	<!--
	  function go_to_url(){
	     window.location.href="http://www.3yx.com:80";
	   }
	   go_to_url();
	//-->
	</script>
  </body>
</html>


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2017-9-23 11:53:23 | 显示全部楼层
标题写错了,登录有跳转 请求有跳转,不知道怎么搞额,请教大神们啊
发表于 2017-9-25 09:47:36 | 显示全部楼层
发表于 2017-10-9 10:43:10 | 显示全部楼层
你这种是js跳转,只能抓取js内容,自己跳转
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-11-22 18:13

© 2014-2021

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