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\" >" + @"([\S\s]*?)" + "</table>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection matchs = rx.Matches(strSource);
if (matchs.Count > )
{
strSource = matchs[].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", @"[\S\s]*?");
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 = ; i < matchs.Count; i++)
{
listBox1.Items.Add(matchs[i].Groups[].Value + "|" + matchs[i].Groups[].Value + "|" + matchs[i].Groups[].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, , 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\" >" + @"([\S\s]*?)" + "</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 > )
{
strSource = matchs[].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", @"[\S\s]*?");
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 = ; i < matchs.Count; i++)
{
listBox1.Items.Add(matchs[i].Groups[].Value + "|" + matchs[i].Groups[].Value + "|" + matchs[i].Groups[].Value.Replace(",", "").Replace("'", "").Replace("(", "").Replace(")", ""));
One.Add(Convert.ToInt32( matchs[i].Groups[].Value), matchs[i].Groups[].Value + "|" + matchs[i].Groups[].Value.Replace(",", "").Replace("'", "").Replace("(", "").Replace(")", ""));
//插入数据库 }
}
} 主页 www.yundll.com


C# 取html <data>内容的更多相关文章

  1. 从kepware定时取web api内容

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. day57作业(包含data内容)

    day57作业 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&quo ...

  3. file_get_contents抓取远程URL内容

    /** * POST URL * @param $url * @param null $post * @return false / string */ public static function ...

  4. Oracle bbed 实用示例-----修改Data内容、恢复delete的rows

    bbed 可以在db open 状态来进行修改,但是建议在做任何修改操作之前先shutdown db. 这样避免checkpoint 进程重写bbed 对block 的修改. 也避免oracle 在b ...

  5. php curl抓取远程页面内容的代码

    使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...

  6. PHPcurl抓取AJAX异步内容(转载)

    PHPcurl抓取AJAX异步内容 其实抓ajax异步内容的页面和抓普通的页面区别不大.ajax只不过是做了一次异步的http请求,只要使用firebug类似的工具,找到请求的后端服务url和传值的参 ...

  7. php爬取微信文章内容

    php爬取微信文章内容 在做官网升级的时遇到新的需求,需要将公司公众号文章显示在官网的文章模块下.但存在的问题是:微信文章的链接会失效,并且需要对文章部分内容做修改,同时要减少微信运营人员的工作量,避 ...

  8. scrapy爬取动态分页内容

    1.任务定义: 爬取某动态分页页面中所有子话题的内容. 所谓"动态分页":是指通过javascript(简称"js")点击实现翻页,很多时候翻页后的页面地址ur ...

  9. js取自定义data属性

    //20170329 原本以为只能attr或者prop来获取属性,但是今天看别人的代码他自定义了一个属性,却取不到他的属性值,我自己在本地又可以取到,难道是phtml的原因,于是我到网上查找,发现了一 ...

随机推荐

  1. Java学习之理解多态

    Java 多态 多态是同一个行为具有多个不同表现形式或形态的能力.多态就是同一个接口,使用不同的实例而执行不同操作,多态性是对象多种表现形式的体现.例如:可以把人分为男人和女人,男人有做力气活的能力, ...

  2. Flask--Config研究

    导入Flask框架后,在项目跟目录下面会有一个Config.py 文件,里面的默认内容为: class Config(object): pass 可以这Config 类里面定义变量和其他对象 如: c ...

  3. NYOJ448寻找最大数,贪心~~

    寻找最大数 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大, 比如当n=92081346718538 ...

  4. [luoguP2982][USACO10FEB]慢下来Slowing down(dfs序 + 线段树)

    传送门 这个题显然可以用树链剖分做. 然而线段树也能做. 每个点都对它的子树有贡献,所以先求一边 dfs序,然后直接在 dfs序 中搞 线段树 就行. ——代码 #include <cstdio ...

  5. Lucene、Compass学习以及与SSH的整合

    一.准备 个人在学习中采用Struts2 + Hibernate3.2 + Spring2.5 + Compass2.2.0, 一下图片为本次学习中用到的jar包: 图中圈出的jar包为本次学习的主要 ...

  6. MySQL事务及Spring事务管理

    事务,是在数据库中用于保证数据正确性的一种机制,涉及到很多概念以及不同的情况,这里做一个总结 相关概念 事务四特性(ACID) 原子性(Atomicity,或称不可分割性):要么全部完成或者全部不完成 ...

  7. 关于oracle存储过程的若干问题备忘

    1.在oracle中,数据表别名不能加as,如: select a.appname from appinfo a;-- 正确select a.appname from appinfo as a;-- ...

  8. Tomcat+Servlet登录页面实例

    概念   Tomcat server是一个免费的开放源码的Web 应用server,属于轻量级应用server,在中小型系统和并发訪问用户不是非常多的场合下被普遍使用,是开发和调试JSP 程序的首选. ...

  9. windows下开发PHP扩展dll(无需Cygwin)

    windows下开发php扩展网上很多资料都说需要Cygwin,其实完全可以不必安装该东东.没错,是可以在linux下生成骨架后拷到windos下来用,但是,如果没有linux环境呢?什么,装虚拟机? ...

  10. Oracle 数据库管理员的任务

    设计.实施和维护 Oracle 数据库时,按优先次序排列的任务包括:   1. 确定数据库服务器硬件   2. 安装 Oracle 软件   3. 为数据库和安全策略制定计划   4. 创建.移植和打 ...