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
    
    
    
    
    
    放下电子产品,每天进步一点点
  • 相关阅读:
    CountDownLatch、CyclicBarrier、Semaphore的区别
    Java最小堆解决TopK问题
    【转载】缓存穿透,缓存击穿,缓存雪崩解决方案分析
    缓存雪崩问题及处理方案
    memcached 缓存数据库应用实践
    Redis分布式锁的正确实现方式
    JVM垃圾回收--年轻代、年老点和持久代(转)
    策略模式—Java实现(转)
    (转) Redis哨兵的详解
    Hibernate中1+N问题以及解决方法
  • 原文地址:https://www.cnblogs.com/vienna/p/4038412.html
Copyright © 2011-2022 走看看