惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
D
DataBreaches.Net
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
Y
Y Combinator Blog
博客园 - 【当耐特】
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
量子位
C
Check Point Blog
F
Fortinet All Blogs
罗磊的独立博客
Last Week in AI
Last Week in AI
GbyAI
GbyAI
L
LangChain Blog
博客园 - 司徒正美

博客园 - Winner.Net(2007)

centos 端口开放及关闭 Can't connect to MySQL server on 'ip' (13) CentOS 6.0 系统 LAMP(Apache+MySQL+PHP)安装步骤 linux 开启 mount PHP与MYSQL事务处理 型B2C电子商务网站组织架构分析 转 PHP _construct _destory _call _get _set等 - Winner.Net(2007) eew CSS+js 实现mouse移动单元格上全部显示 web2.0网站的性能优化方法 (转) Web应用性能优化黄金法则——转 js编码处理(转) 服务器推技术 网页标签解析 转http状态码 观察者+js 模式 - Winner.Net(2007) - 博客园 JS倒计时 - Winner.Net(2007) - 博客园 sql得到时间 EXT 列头合并的例子 - Winner.Net(2007) - 博客园
登陆抓取数据 - Winner.Net(2007) - 博客园
Winner.Net(2 · 2009-04-27 · via 博客园 - Winner.Net(2007)

            string url1 = @"http://login.vancl.com/Login/";                   //提交注册信息的网址
            string url2 = @"http://my.vancl.com/User/User_Order_List.aspx";    //需要下载的网页

            string indata = "mailto:Logintrue=true&UserName=jsycywm@hotmail.com&PassWord=我的密码&x=45&y=15";

            CookieContainer myCookieContainer = new CookieContainer();                      //新建一个CookieContainer来存放Cookie集合
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url1);      //新建一个HttpWebRequest
            myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
            myHttpWebRequest.ContentLength = indata.Length;
            //myHttpWebRequest.ac
            myHttpWebRequest.Method = "POST";
            myHttpWebRequest.CookieContainer = myCookieContainer;                           //设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainer
            Stream myRequestStream = myHttpWebRequest.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("GB2312"));
            myStreamWriter.Write(indata);           //把数据写入HttpWebRequest的Request流

            myStreamWriter.Close();
            myRequestStream.Close();                //关闭打开对象


            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();        //新建一个HttpWebResponse
            myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);      //获取一个包含url的Cookie集合的CookieCollection
            Stream myResponseStream = myHttpWebResponse.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8 );
            string outdata = myStreamReader.ReadToEnd();//把数据从HttpWebResponse的Response流中读出
            myStreamReader.Close();
            myResponseStream.Close();
            //Console.WriteLine(outdata);//显示"登录"
            //拿到了Cookie,再进行请求就能直接读取到登录后的内容了
            myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url2);
            myHttpWebRequest.CookieContainer = myCookieContainer;//*
            //刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证
            myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
            myResponseStream = myHttpWebResponse.GetResponseStream();
            myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
            outdata = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            //Response.Redirect(url2);
            //Console.WriteLine(outdata);
            //再次显示"登录"
            //如果把*行注释调,就显示"没有登录"
            string abc = outdata.Substring(413, outdata.Length - 413 - 11); //.Replace("title", "tag")
            //  abc = Regex.Replace(abc,"<!--User_Interface End-->.*?<!--Bottom-->" , "");//"title=\".*?\"|title='.*?'|<img.*?\">"
            Match mc = Regex.Match(abc, "<table>.*?/table>");//<div id=\"main\">.*?</div>  Regex.Matches(abc, "<table>.*?/table>")[0].Value
            abc = Regex.Replace(mc.Value, "<thead>.*?thead>", "");
         // MatchCollection results
 
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(abc );
            XmlNode xn = xmlDoc.SelectSingleNode("table");
            XmlElement xe = (XmlElement)xn;
            //xn.ChildNodes[0].ChildNodes[1].InnerText 
            //xn.ChildNodes.Count
            string result = xe.InnerText;