【C#】Get the html code of a webpage
As for the title,the console program will show you a sample which can get the webpage-code.Enjoy it:)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- using System.IO;
- using System.Runtime.InteropServices; //dllimport relies on it
- namespace WebPageCode
- {
- class Program
- {
- [DllImport("kernel32.dll")]
- static extern uint GetTickCount();
- static void addhead(ref string px) //add http head if necessary
- {
- if (px.Substring(, ).ToLower() != @"http://") px = @"http://" + px;
- }
- static string getwebcode(string PageUrl,string proxy=""){
- uint x = GetTickCount();
- addhead(ref PageUrl); //webpage check
- WebClient wc = new WebClient();
- wc.Credentials = CredentialCache.DefaultCredentials;
- proxy.Trim(); //proxy check
- if (proxy != "")
- {
- addhead(ref proxy);
- WebProxy wp = new WebProxy();
- wp.Address = new Uri(proxy);
- wc.Proxy = wp;
- }
- Byte[] pageData = wc.DownloadData(PageUrl);
- x = GetTickCount() - x; //x means the time spent.
- return Encoding.UTF8.GetString(pageData);
- }
- static void Main(string[] args)
- {
- int i = , n = args.Length;
- string proxy = "";
- string page = "";
- while (i < n)
- {
- if (args[i] == "-proxy")
- {
- if (i<(n-)) proxy = args[++i];
- }
- if (args[i] == "-page")
- {
- if (i < (n - )) page = args[++i];
- }
- i++;
- }
- page.Trim(); proxy.Trim();
- if (page == "") return; //no webpage found
- string code;
- if (proxy == ""){
- code=getwebcode(page); //proxy found
- } else {
- code=getwebcode(page,proxy); //no proxy found
- }
- Console.Write(code);
- Console.ReadKey();
- }
- }
- }
【C#】Get the html code of a webpage的更多相关文章
- 【JS】Advanced1:Object-Oriented Code
Object-Oriented Code 1. var Person = function (name) { this.name = name; }; Person.prototype.say = f ...
- 【cocos2d-x】尝鲜 Cocos Code IDE(不断更新)
Cocos Code IDE 是一个基于 Eclipse 的跨平台 IDE ,专门为 cocos2d lua & js 开发者准备,通过此工具.你能够方便的创建游戏project.编写而且调试 ...
- 【转】vscode: Visual Studio Code 常用快捷键
原文链接:https://www.cnblogs.com/bindong/p/6045957.html vscode: Visual Studio Code 常用快捷键 主命令框 F1 或 Ctrl+ ...
- 【译】第5节---Code First约定
原文:http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx 我们在上一节中已经看到了EF Code ...
- 【PowerDesigner】【9】禁止Name与Code同步
问题:修改了某个字段的name,其code也跟着修改 步骤:Tools→General Options..→Dialog→取消勾选“Name to Code mirroring”复选框 参考博客: 1 ...
- 【题解】Popping Balls AtCoder Code Festival 2017 qual B E 组合计数
蒟蒻__stdcall终于更新博客辣~ 一下午+一晚上=一道计数题QAQ 为什么计数题都这么玄学啊QAQ Prelude 题目链接:这里是传送门= ̄ω ̄= 下面我将分几个步骤讲一下这个题的做法,大家不 ...
- 【Leetcode】804. Unique Morse Code Words
Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...
- 【微信】根据appid, secret, code获取用户基本信息
function getUserInfo(){ $appid = "yourappid"; $secret = "yoursecret"; $code = $_ ...
- 【转载】Why Learning to Code is So Damn Hard By Erik Trautman
原文网址:https://www.thinkful.com/blog/why-learning-to-code-is-so-damn-hard/ 在罗老师的<算法竞赛 入门到进阶>总看到了 ...
随机推荐
- 记第五届山东省ACM程序设计比赛——遗憾并非遗憾
记第五届山东省ACM程序设计比赛 5月10日上午9点半左右,我们的队伍从学校出发,一个多小时后到达本次比赛的地点-哈尔滨工业大学. 报道,领材料,吃午饭,在哈工大的校园里逛了逛,去主楼的自习室歇息了一 ...
- Lucene.net入门学习
Lucene.net入门学习(结合盘古分词) Lucene简介 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全 ...
- 使用javaservice 将jboss 注册为服务
近来做项目,需要jboss定期重新启动.不想再看到jboss启动那个黑洞洞的窗口,就想着把它注册为服务,然后在net start.恰好objectweb上有个open source的javaservi ...
- Java 感知Mysql存储过程变量数量
在项目中,可能会遇到sybase 移植到 mysql的情况,因为sybase 支持存储过程的可变参数,而mysql不能支持,所以,在调用mysql的时候,需要感知存储过程到底有几个参数,来合理的配置参 ...
- ASP.NET MVC 缓存扩展 - Donut Caching
项目介绍 ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code ...
- JAVA学习:多态
多态:可以理解为事物存在的多种体现形态. 人:男人,女人 动物:猫,狗. 猫 x = new 猫(); 动物 x = new 猫() 1,多态的体现 父类的引用指向了自己的子类对象. 父类的引 ...
- sqlserver中数据的四种插入方式
1.insert into stuInfo(name,stuId) values('李洁','19291727')insert into stuInfo(name,stuId) values('李康' ...
- 迁移Model元数据设置项
.NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序) 阅读目录: 1.需求背景介绍(Model元数据设置项应该与View绑定而非ViewModel) 1 ...
- iOS基础 - 史上最难游戏
步骤一:隐藏状态栏 步骤二:屏幕适配 步骤三:设置窗口的根控制器为导航控制器,并且设置导航条和状态栏. 步骤四:搭建设置界面 步骤五:控制器连线 步骤六:搭建关卡控制器 加载pilst文件 创建关卡模 ...
- Binder机制,从Java到C (4. Parcel)
1. 远程调用的数据传输 在远程的函數中,必然会需要传递一些数据,那这些数据是怎么传输的呢? 在IPC中,Proxy端的作用就是将一些参数打包,然后发送出去,下面是在Proxy端经常会遇见的调用远程方 ...