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\" >" + @"([\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>内容的更多相关文章
- 从kepware定时取web api内容
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- day57作业(包含data内容)
day57作业 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&quo ...
- file_get_contents抓取远程URL内容
/** * POST URL * @param $url * @param null $post * @return false / string */ public static function ...
- Oracle bbed 实用示例-----修改Data内容、恢复delete的rows
bbed 可以在db open 状态来进行修改,但是建议在做任何修改操作之前先shutdown db. 这样避免checkpoint 进程重写bbed 对block 的修改. 也避免oracle 在b ...
- php curl抓取远程页面内容的代码
使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...
- PHPcurl抓取AJAX异步内容(转载)
PHPcurl抓取AJAX异步内容 其实抓ajax异步内容的页面和抓普通的页面区别不大.ajax只不过是做了一次异步的http请求,只要使用firebug类似的工具,找到请求的后端服务url和传值的参 ...
- php爬取微信文章内容
php爬取微信文章内容 在做官网升级的时遇到新的需求,需要将公司公众号文章显示在官网的文章模块下.但存在的问题是:微信文章的链接会失效,并且需要对文章部分内容做修改,同时要减少微信运营人员的工作量,避 ...
- scrapy爬取动态分页内容
1.任务定义: 爬取某动态分页页面中所有子话题的内容. 所谓"动态分页":是指通过javascript(简称"js")点击实现翻页,很多时候翻页后的页面地址ur ...
- js取自定义data属性
//20170329 原本以为只能attr或者prop来获取属性,但是今天看别人的代码他自定义了一个属性,却取不到他的属性值,我自己在本地又可以取到,难道是phtml的原因,于是我到网上查找,发现了一 ...
随机推荐
- java环境配置——工具下载地址
每次官网找个下载地址都是 费劲巴拉的 整理了一下几个下载地址分享给大家 eclipse:http://www.eclipse.org/downloads/packages/release/Kepler ...
- cf839c Journey
大水题 #include <iostream> #include <cstdio> using namespace std; int n, du[100005], hea[10 ...
- Java高级程序员面试题
1.你认为项目中最重要的过程是那些? 分析.设计阶段 尽量找出进度的优先级 2.如果给你一个4-6人的team,怎么分配? 挑选一技术过硬的人作为我的替补.其它人平均分配任务,每周进行全面的任务分配 ...
- python003 Python3 基本数据类型
Python3 基本数据类型Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建.在 Python 中,变量就是变量,它没有类型,我们所说的"类型&qu ...
- [luoguP2982][USACO10FEB]慢下来Slowing down(dfs序 + 线段树)
传送门 这个题显然可以用树链剖分做. 然而线段树也能做. 每个点都对它的子树有贡献,所以先求一边 dfs序,然后直接在 dfs序 中搞 线段树 就行. ——代码 #include <cstdio ...
- hdu 3879 最大密集子图(点和边均带权)(模板)
/* 最大权闭合图,可以用最大密集子图来解速度更快复杂度低 题解:胡伯涛<最小割模型在信息学竞赛中的应用> 点和边均带权的最大密集子图 s-i,权为U=点权绝对值和+边的所有权值 i-t, ...
- Java 学习(4):基本数据类型,变量类型
目录 --- 基本数据类型 --- 变量类型 基本数据类型 变量就是申请内存来存储值.也就是说,当创建变量的时候,需要在内存中申请空间. 内存管理系统根据变量的类型为变量分配存储空间,分配的空间只能用 ...
- POJ 1017 Packet
http://poj.org/problem?id=1017 有1*1 2*2...6*6的物品 要装在 6*6的parcel中 问最少用多少个parcel 一直没有找到贪心的策略 问题应该出现在 总 ...
- CodeForces - 750D New Year and Fireworks
因为 烟花的最大范围是各个方向150格 所以 最大的空间应该是 300*300 BFS和DFS均可 模拟每一个烟花爆炸的过程 但是要注意 需要一个数组来排重 在某一个爆炸点 如果爆炸的方向 和爆炸的层 ...
- Codevs 1688 求逆序对
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定一个序列a1,a2,…,an,如果存在i<j并且ai>aj,那么我 ...