抓取网页数据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 应用程序不一定要自己去提供数据. ...
随机推荐
- 剖析ASP.NET Core MVC(Part 1)- AddMvcCore(译)
原文:https://www.stevejgordon.co.uk/asp-net-core-mvc-anatomy-addmvccore发布于:2017年3月环境:ASP.NET Core 1.1 ...
- 二十四种设计模式:单例模式(Singleton Pattern)
单例模式(Singleton Pattern) 介绍保证一个类仅有一个实例,并提供一个访问它的全局访问点. 示例保证一个类仅有一个实例. Singleton using System; using S ...
- jquery dialog close icon missing 关闭图片丢失,样式丢失问题
http://stackoverflow.com/questions/17367736/jquery-ui-dialog-missing-close-icon
- python scikit-learn选择正确估算器
下图摘自官方文档 链接 http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html
- Add Two Numbers(from leetcode python 链表)
给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将两数相加返回一个新的链表. 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 示例: 输入:(2 -& ...
- http 使用curl发起https请求报错的解决办法
使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:1409008 ...
- css border-sizing 用法与理解
浏览器支持 IE Firefox Chrome Safari Opera 支持 支持 支持 支持 支持 Internet Explorer.Opera 以及 Chrome 支持 box-si ...
- 菜单下拉效果demo记录
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content ...
- ListView改变字体
ListView中没有改变字体的属性和方法,所以需要用其他的方式.这里使用ArrayAdapter. 首先,创建一个TextView组件,用来作为Adapter的列表项组件. 在layout文 ...
- Android 如何增大开机铃声 M
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...