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#文件的更多相关文章

  1. PHP利用Curl实现多线程抓取网页和下载文件

    PHP 利用 Curl  可以完成各种传送文件操作,比如模拟浏览器发送GET,POST请求等等,然而因为php语言本身不支持多线程,所以开发爬虫程序效率并不高,一般采集 数据可以利用 PHPquery ...

  2. 01 UIPath抓取网页数据并导出Excel(非Table表单)

    上次转载了一篇<UIPath抓取网页数据并导出Excel>的文章,因为那个导出的是table标签中的数据,所以相对比较简单.现实的网页中,有许多不是通过table标签展示的,那又该如何处理 ...

  3. java抓取网页数据,登录之后抓取数据。

    最近做了一个从网络上抓取数据的一个小程序.主要关于信贷方面,收集的一些黑名单网站,从该网站上抓取到自己系统中. 也找了一些资料,觉得没有一个很好的,全面的例子.因此在这里做个笔记提醒自己. 首先需要一 ...

  4. Asp.net 使用正则和网络编程抓取网页数据(有用)

    Asp.net 使用正则和网络编程抓取网页数据(有用) Asp.net 使用正则和网络编程抓取网页数据(有用) /// <summary> /// 抓取网页对应内容 /// </su ...

  5. 使用HtmlAgilityPack批量抓取网页数据

    原文:使用HtmlAgilityPack批量抓取网页数据 相关软件点击下载登录的处理.因为有些网页数据需要登陆后才能提取.这里要使用ieHTTPHeaders来提取登录时的提交信息.抓取网页  Htm ...

  6. web scraper 抓取网页数据的几个常见问题

    如果你想抓取数据,又懒得写代码了,可以试试 web scraper 抓取数据. 相关文章: 最简单的数据抓取教程,人人都用得上 web scraper 进阶教程,人人都用得上 如果你在使用 web s ...

  7. c#抓取网页数据

    写了一个简单的抓取网页数据的小例子,代码如下: //根据Url地址得到网页的html源码 private string GetWebContent(string Url) { string strRe ...

  8. 使用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 ...

  9. 【iOS】正則表達式抓取网页数据制作小词典

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/xn4545945/article/details/37684127 应用程序不一定要自己去提供数据. ...

随机推荐

  1. MLP 之手写数字识别

    0. 前言 前面我们利用 LR 模型实现了手写数字识别,但是效果并不好(不到 93% 的正确率). LR 模型从本质上来说还只是一个线性的分类器,只不过在线性变化之后加入了非线性单调递增 sigmoi ...

  2. mac下如何全量删除短信内容

    退出messages应用 执行命令:rm -r ~/Library/Messages/chat.* 重启messages 如果遇到下面问题:重启mac

  3. Oracle两个时间段是否重合、冲突

    经常会碰到比较两个时间段是否冲突的情况. 思路1 最开始比较2个时间是否的思路是,时间段的重叠.  但是比较时间段重叠的情况,就有几种情况, 1. 时间前段冲突.   时间A:  2015-10-01 ...

  4. jersey rest webservice

    参考官网:https://jersey.github.io/documentation/latest/getting-started.html#new-webapp 创建一个 JavaEE Web A ...

  5. http 使用curl发起https请求报错的解决办法

    使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:1409008 ...

  6. Java笔记11:JSP连接Oracle数据库

    1 建立Web项目 在D:\tomcat\webapps\中建立basicSyntax项目,在该项目中添加WEB-INF,WEB-INF\classes\,WEB-INF\lib\和WEB-INF\w ...

  7. 30分钟Git命令“从入门到放弃”

    git 现在的火爆程度非同一般,它被广泛地用在大型开源项目中,但是初学者非常容易“从入门到放弃”,各种命令各种参数,天哪,宝宝要吓哭了.实际上新手并不需要了解所有命令的用途,学习是需要一个循序渐进的过 ...

  8. An incompatible version 1.1.14 of APR based Apache Tomcat Native library is installed, while Tomcat

    启动tomcat 7.0, 看到日志里出现严重警告, An incompatible version 1.1.14 of APR based Apache Tomcat Native library ...

  9. 一个tomcat中部署多个项目

    在各自的项目web.xml中添加 <context-param> <param-name>webAppRootKey</param-name> <param- ...

  10. com.android.support冲突的解决办法

    All com.android.support libraries must use the exact same version specification (mixing versions can ...