zoukankan      html  css  js  c++  java
  • C# 取html <data>内容

      private void button1_Click(object sender, EventArgs e)
            {
                string strSource = GetHttpWebRequest("http://www.******.aspx");
    
                //匹配出表格内容
                Regex rx = new Regex("<table width="936" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFB91F" align="center" style="color:Black;" id="panel" >" + @"([Ss]*?)" + "</table>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                MatchCollection matchs = rx.Matches(strSource);
                if (matchs.Count > 0)
                {
                    strSource = matchs[0].Value;
                    string pattern = "<tr align="center" bgcolor="#@all">@all<td height="32" bgcolor="#@all">(.*)</td>@all<td height="28" bgcolor="#@all">(.*)</td>@all<td bgcolor="#@all">@allchkResult(.*);</script></td>@all</tr>";
                    pattern = pattern.Replace("@all", @"[Ss]*?");
                    rx = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    //将匹配出的数据放入DataTable
                    DataRow drow;
                    matchs = rx.Matches(strSource);
    
                    //MessageBox.Show(matchs[0].Groups[1].Value);
                    for (int i = 0; i < matchs.Count; i++)
                    {
                        listBox1.Items.Add(matchs[i].Groups[1].Value + "|" + matchs[i].Groups[2].Value + "|" + matchs[i].Groups[3].Value.Replace(",","").Replace("'","").Replace("(","").Replace(")",""));
    
                    }
                }
            }

    带条件的取
      private void GetData(int cout)
            {
                string postData2;
                HttpWebRequest requestScore = (HttpWebRequest)WebRequest.Create("http://www.******.aspx");
               // postData2 = "__VIEWSTATE=%2FwEPDwUJNzc3MTAxMzU5ZGRoqAvv8WszDJmdGj4cP0O2gODj8g%3D%3D&soundshow=&reloadshow=&CurrentPageIndex="+cout.ToString();
                byte[] data  = Encoding.ASCII.GetBytes(postData2);
                requestScore.Method = "Post";
                requestScore.ContentType = "application/x-www-form-urlencoded";
                requestScore.ContentLength = data.Length;
                requestScore.KeepAlive = true;
    
                //使用登陆的cookies通过接下来的验证
                //requestScore.CookieContainer = container;
                Stream stream = requestScore.GetRequestStream();
                stream.Write(data, 0, data.Length);
                stream.Close();
                HttpWebResponse responseSorce = (HttpWebResponse)requestScore.GetResponse();
                StreamReader reader = new StreamReader(responseSorce.GetResponseStream(), Encoding.Default);
                string strSource = reader.ReadToEnd();
                Regex rx = new Regex("<table width="936" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFB91F" align="center" style="color:Black;" id="panel" >" + @"([Ss]*?)" + "</table>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                //<table width="936" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFB91F" align="center" style="color:Black;" id="panel" >
                MatchCollection matchs = rx.Matches(strSource);
                if (matchs.Count > 0)
                {
                    strSource = matchs[0].Value;
                    string pattern = "<tr align="center" bgcolor="#@all">@all<td height="32" bgcolor="#@all">(.*)</td>@all<td height="28" bgcolor="#@all">(.*)</td>@all<td bgcolor="#@all">@allchkResult(.*);</script></td>@all</tr>";
                    pattern = pattern.Replace("@all", @"[Ss]*?");
                    rx = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    //将匹配出的数据放入DataTable
                    DataRow drow;
                    matchs = rx.Matches(strSource);
    
                    //MessageBox.Show(matchs[0].Groups[1].Value);
                    for (int i = 0; i < matchs.Count; i++)
                    {
                        listBox1.Items.Add(matchs[i].Groups[1].Value + "|" + matchs[i].Groups[2].Value + "|" + matchs[i].Groups[3].Value.Replace(",", "").Replace("'", "").Replace("(", "").Replace(")", ""));
                        One.Add(Convert.ToInt32( matchs[i].Groups[1].Value), matchs[i].Groups[2].Value + "|" + matchs[i].Groups[3].Value.Replace(",", "").Replace("'", "").Replace("(", "").Replace(")", ""));
                        //插入数据库
                        
                    }
                }
            }

    主页 www.yundll.com
    
    
    
    
    
    放下电子产品,每天进步一点点
  • 相关阅读:
    巩固复习(对以前的随笔总结)_01
    Django 项目分析后得到的某些结论
    django 命令行命令
    实现搜索视频到播放(非原创)
    python 打包
    随笔汇总,温故知新
    找伙伴
    sam-Toy Cars
    反质数
    Blue Mary的战役地图
  • 原文地址:https://www.cnblogs.com/vienna/p/4038412.html
Copyright © 2011-2022 走看看