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的原因,于是我到网上查找,发现了一 ...
随机推荐
- 大数据学习——Linux-SSH报错:Could not resolve hostname centos02: Temporary failure in name resolution
https://blog.csdn.net/mcb520wf/article/details/83303792 随笔异常 ssh: Could not resolve hostname centos0 ...
- 调用hcm接口同步员工数据更新员工信息没有同步到bdm
原来是更新的时候,baseEmployeeEntity的id为空,这时候需要把原先的baseEmployeeEntity1的id赋值给baseEmployeeEntity,问题解决
- python自定义模块导入方法,文件夹,包的区别
python模块导入,网上介绍的资料很多,方法也众说纷纭.根据自己的实践,感觉这个方法最简单直接,而且可以与主流的python ide生成的工程是一样的. 规则只有三条 1. 严格区分包和文 ...
- python024 Python3 实例
Python3 实例 以下实例在 Python3.4.3 版本下测试通过: Python Hello World 实例 Python 数字求和 Python 平方根 Python 二次方程 Pytho ...
- java常见问题集锦
Eclipse 编译错误 Access restriction:The type *** is not accessible due to restriction on... 解决方案 Eclipse ...
- NIUDAY 11.23 北京站抢票啦 | 看 AI 落地行业 享 AI 时代红利
2018 年是见证「奇迹」的一年.AI 从多年的热门话题中开始走下神坛,逐渐深入到了各个行业,加速经济结构优化及行业智慧化升级,AI 已不再是难以企及的神话而是可触摸的美好未来. 政策支持加上资本推动 ...
- Uva10294 Arif in Dhaka (置换问题)
扯回正题,此题需要知道的是置换群的概念,这点在刘汝佳的书中写的比较详细,此处不多做赘述.此处多说一句的是第二种手镯的情况.在下图中“左图顺时针转1个位置”和“右图顺时针旋转5个位置”是相同的,所以在最 ...
- nginx反向代理ajax,解决跨域问题
server { listen 8000; server_name somename alias another.alias; location /a { add_header 'Access-Con ...
- 0c-适配 iOS 11
参考路径:https://mp.weixin.qq.com/s?__biz=MzA3NTYzODYzMg==&mid=2653579210&idx=1&sn=d5ea8d46c ...
- Sublime3 Preference, Settings-User
{"font_face": "Consolas","font_size": 15,"ignored_packages": ...