抓取网页数据C#文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
using System.Net;
using System.IO;
namespace WebJSON.Controllers
{
public class LibraryController : Controller
{
//
// GET: /Library/
public String Index( )
{
string pageHtml;
String value="";
List<String> a = new List<String>();
try {
WebClient MyWebClient = new WebClient();
MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
Byte[] pageData = MyWebClient.DownloadData("http://lib.ecust.edu.cn:8081/GATESEAT/LRP.ASPX"); //从指定网站下载数据
// string pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句
pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句
Regex reg = new Regex("\">(.*)</f");
MatchCollection mc = reg.Matches(pageHtml);
foreach (Match match in mc)
{
a.Add(match.Value);
value = value + match.Value;
}
String floor1 = a[2].Remove(0, 36);//1楼人数
floor1 = floor1.Remove(floor1.Length-3,3);
String floor12 = a[3].Remove(0, 36);//1楼剩余座位
floor12 = floor12.Remove(floor12.Length-3,3);
String floor21 = a[5].Remove(0, 36);//2楼人数
floor21 = floor21.Remove(floor21.Length - 3, 3);
String floor22 = a[6].Remove(0, 36);//2楼剩余座位
floor22 = floor22.Remove(floor22.Length - 3, 3);
String floor31 = a[8].Remove(0, 36);//3楼人数
floor31 = floor31.Remove(floor31.Length - 3, 3);
String floor32 = a[9].Remove(0, 36);//3楼剩余座位
floor32 = floor32.Remove(floor32.Length - 3, 3);
String floor41 = a[11].Remove(0, 36);//4楼人数
floor41 = floor41.Remove(floor41.Length - 3, 3);
String floor42 = a[12].Remove(0, 36);//4楼剩余座位
floor42 = floor42.Remove(floor42.Length - 3, 3);
String floor51 = a[14].Remove(0, 36);//5楼人数
floor51 = floor51.Remove(floor51.Length - 3, 3);
String floor52 = a[15].Remove(0, 36);//5楼剩余座位
floor52 = floor52.Remove(floor52.Length - 3, 3);
String floor61 = a[17].Remove(0, 36);//6楼人数
floor61 = floor61.Remove(floor61.Length - 3, 3);
String floor62 = a[18].Remove(0, 36);//6楼剩余座位
floor62 = floor62.Remove(floor62.Length - 3, 3);
return floor41 + floor42 + floor51 + floor52 + floor61 + floor62;
}
catch(WebException webEx) {
return "0";
}
}
}
}
抓取网页数据C#文件的更多相关文章
- PHP利用Curl实现多线程抓取网页和下载文件
PHP 利用 Curl 可以完成各种传送文件操作,比如模拟浏览器发送GET,POST请求等等,然而因为php语言本身不支持多线程,所以开发爬虫程序效率并不高,一般采集 数据可以利用 PHPquery ...
- 01 UIPath抓取网页数据并导出Excel(非Table表单)
上次转载了一篇<UIPath抓取网页数据并导出Excel>的文章,因为那个导出的是table标签中的数据,所以相对比较简单.现实的网页中,有许多不是通过table标签展示的,那又该如何处理 ...
- java抓取网页数据,登录之后抓取数据。
最近做了一个从网络上抓取数据的一个小程序.主要关于信贷方面,收集的一些黑名单网站,从该网站上抓取到自己系统中. 也找了一些资料,觉得没有一个很好的,全面的例子.因此在这里做个笔记提醒自己. 首先需要一 ...
- Asp.net 使用正则和网络编程抓取网页数据(有用)
Asp.net 使用正则和网络编程抓取网页数据(有用) Asp.net 使用正则和网络编程抓取网页数据(有用) /// <summary> /// 抓取网页对应内容 /// </su ...
- 使用HtmlAgilityPack批量抓取网页数据
原文:使用HtmlAgilityPack批量抓取网页数据 相关软件点击下载登录的处理.因为有些网页数据需要登陆后才能提取.这里要使用ieHTTPHeaders来提取登录时的提交信息.抓取网页 Htm ...
- web scraper 抓取网页数据的几个常见问题
如果你想抓取数据,又懒得写代码了,可以试试 web scraper 抓取数据. 相关文章: 最简单的数据抓取教程,人人都用得上 web scraper 进阶教程,人人都用得上 如果你在使用 web s ...
- c#抓取网页数据
写了一个简单的抓取网页数据的小例子,代码如下: //根据Url地址得到网页的html源码 private string GetWebContent(string Url) { string strRe ...
- 使用JAVA抓取网页数据
一.使用 HttpClient 抓取网页数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...
- 【iOS】正則表達式抓取网页数据制作小词典
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/xn4545945/article/details/37684127 应用程序不一定要自己去提供数据. ...
随机推荐
- Linux的进程间通信-文件和文件锁
前言 使用文件进行进程间通信应该是最先学会的一种IPC方式.任何编程语言中,文件IO都是很重要的知识,所以使用文件进行进程间通信就成了很自然被学会的一种手段.考虑到系统对文件本身存在缓存机制,使用文件 ...
- Jpeglib读取jpg文件 【转】
http://blog.csdn.net/blues1021/article/details/45424695 整理自 : http://hi.baidu.com/lewutian/item/e8ee ...
- transparent shadow caster unity
https://forum.unity.com/threads/semitransparent-shadows.276490/ semitransparent shadows dither 类似alp ...
- Hadoop数据目录迁移
Hadoop数据目录迁移 @(Hadoop) 随着数据的不断导入和增大,原本集群部署的目录磁盘空间不足了,所以要把hadoop存储数据的位置迁移到另外一个巨大的磁盘上,另外的一个用意是将数据和程序分离 ...
- [HTML5] Track First Contentful Paint with PerformanceObserver and Google Analytics
"If you can't measure it, you can't improve it." The first step when doing performance wor ...
- PHP过滤器
这里介绍的过滤器包括: 1.filter_input 2.filter_input_array 3.filter_var 4.filter_var_array 5.filter_has_var 一.查 ...
- 刻录车载CD音乐光盘的历程
1.买盘 车载CD播放器不支持读可重复擦写的光盘,所以买了sony的DVD+R 4.7G(它是用来存储数据和视频的),买错了,刻了车载CD播放器也不能播放(苦笑脸#).之后又买CD+R. 2.下载歌曲 ...
- 关于nodejs中npm命令没有反应的解决方法
最近在学习angularJS,正在做一个单页面应用,在安装nodejs之后,发现命令行传了输入npm -v能输出结果外,其余npm的任何操作都没有反应,一开始我以为是下载的比较慢,等了半小时还是没动静 ...
- 欧洲顶级音频播放软件AIMP
http://zmingcx.com/europes-top-software-aimp-audio-player.html 音频播放软件众多,耳熟能详的Winamp.Foobar2000.千千静听. ...
- EMQ 学习---订阅$SYS主题,捕获客户端上下线消息
acl.config文件定义了可订阅$SYS主题的权限. {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]} ...