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的原因,于是我到网上查找,发现了一 ...
随机推荐
- 解决hibernate产生的id序列或者setXX不能同步到数据库到问题(this.hibernateTemplate.flush();hibernateTemplate.getSessionFactory().getCurrentSession().connection().commit())
通过WarehouseInventoryPreLog warehouseInventoryPreLog = new WarehouseInventoryPreLog();产生一个id序列 如果不flu ...
- Python requests.post方法中data与json参数区别
在通过requests.post()进行POST请求时,传入报文的参数有两个,一个是data,一个是json. data与json既可以是str类型,也可以是dict类型. 区别: 1.不管json是 ...
- Mysql学习总结(44)——Linux下如何实现mysql数据库每天自动备份定时备份
概述 备份是容灾的基础,是指为防止系统出现操作失误或系统故障导致数据丢失,而将全部或部分数据集合从应用主机的硬盘或阵列复制到其它的存储介质的过程.而对于一些网站.系统来说,数据库就是一切,所以做好 ...
- POJ 1724 二维费用最短路
题目大意:有N个城市,编号1-N有R条路,每条路(单向)的起点为Si,终点为Di,长度为Li,如果要走这条路需要花Ti的钱现在你只有K元钱,求在不超支的前提下,从1走到N需要的最短距离 这里总是希望路 ...
- hdu 1043 A*
http://www.cnblogs.com/183zyz/archive/2011/08/12/2135827.html #include<stdio.h> #define N 3630 ...
- iview自定义配置
说明 iview是一套基于 Vue.js 的高质量 UI 组件库.主要用户PC端页面设计. 官网:https://www.iviewui.com/ 1.在vue-cli项目中,添加该框架 第一步,安装 ...
- 自用的博客皮肤CSS代码
是在默认皮肤simple memory的基础上进行的魔改 /*****home和头部开始**************************/ #home { margin: 0 auto; widt ...
- POJ 2109 Power of Cryptography【高精度+二分 Or double水过~~】
题目链接: http://poj.org/problem?id=2109 参考: http://blog.csdn.net/code_pang/article/details/8263971 题意: ...
- 【Java源码】集合类-ArrayList
一.类继承关系 public class ArrayList<E> extends AbstractList<E> implements List<E>, Rand ...
- OO第三单元总结——JML
目录 写在前面 JML理论基础 JML工具链 JMLUnitNG的使用 架构设计 Bug分析 心得体会 写在前面 OO的第三单元学习结束了,本单元我们学习了如何使用JML语言来对我们的程序进行规格化设 ...