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的原因,于是我到网上查找,发现了一 ...
随机推荐
- MySQL 存储 utf8mb4
1.如果是阿里云数据库 a.控制台->修改参数character_set_server参数为UTF8mb4 b.设置库的字符集为UTF8mb4 2.如果是自己mysql服务器 [client] ...
- ArrayList集合的增删改查方法
新建一个myArrayList项目 在myArrayList项目下创建一个包 包中创建一个ArrayListDemo2.java文件 ArrayListDemo2.java import java.u ...
- 大数据学习——hive基本操作
1 建表 create table student(id int,name string ,age int) row format delimitedfields terminated by ','; ...
- BNU 13174 Substring Frequency
3C. Substring Frequency Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %lld ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!
A. Santa Claus and a Place in a Class 模拟题.(0:12) 题意:n列桌子,每列m张桌子,每张桌子一分为2,具体格式看题面描述.给出n,m及k.求编号为k的桌子在 ...
- 校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛(Problem E)
Problem E Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- PTA 02-线性结构2 一元多项式的乘法与加法运算 (20分)
原题地址 https://pta.patest.cn/pta/test/15/exam/4/question/710 5-2 一元多项式的乘法与加法运算 (20分) 设计函数分别求两个一元多项式的 ...
- AI Gossip
本文作者:七牛云人工智能实验室-林亦宁原文地址:https://zhuanlan.zhihu.com/p/26168331 什么是智能 回到几万年前的东非大草原,谁能意识到,那个到处被欺负的,被表哥从 ...
- _063_Android_Android内存泄露
深入内存泄露 Android应用的内存泄露,其实就是java虚拟机的堆内存泄漏. 当然,当应用有ndk,jni时,没有及时free,本地堆也会出现内存泄漏. 本文只是针对JVM内存泄漏应用,进行阐述分 ...
- Vim command handbook
/* 本篇文章已经默认你通过了vimtuor训练并能熟练使用大部分命令.此篇文章主要是对于tutor命令的总结和梳理.适合边学习边记忆 tutor那个完全是在学习中记忆 符合认知规律但是练习有限.所以 ...