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
    
    
    
    
    
    放下电子产品,每天进步一点点
  • 相关阅读:
    Android代码执行adb shell top命令读取结果
    Android8.0+跨应用发送广播和跨应用启动前台服务
    Android代码执行adb shell命令
    关于参数获取的那些事儿
    c# 如何处理自定义消息
    esp32 mqtt协议上报 dht11温湿度数据到onenet 指令下发控制开关灯
    swoole-simps自搭mqtt服务器,完美实现订阅,发布并存到mysql
    stm32f103c8t6+esp8266+dht11 mqtt上传温湿度到阿里云
    使用ST-Link下载程序出现Error:Flash Download Failed-“Cortex-M3“ 解决详细步骤(附图)
    stm32f407 oled iic例程,成功点亮oled屏
  • 原文地址:https://www.cnblogs.com/vienna/p/4038412.html
Copyright © 2011-2022 走看看