【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/ 在罗老师的<算法竞赛 入门到进阶>总看到了 ...
随机推荐
- 大约PF_RING/Intel 82599/透明VPN一些事
接近崩溃的边缘,如今,在医院这篇文章地方的想法,小病,我宁愿不吃药瓶.一台笔记本电脑,但无法上网,我不称职.想知道的东西.唯一可用3G,不开的热点.由于没人给我报销流程.这个周末,我只有一天,由于下雨 ...
- LeetCode之Reverse Words in a String
1.(原文)问题描述 Given an input string, reverse the string word by word. For example, Given s = "the ...
- AngularJS Change Path Without Reloading
To change path URL with AngularJS, $location.path() is passed the new URL as a parameter, and the pa ...
- 关于ListView中convertView的缓存个数的探究
在面试的时候经常会被问到一个有关ListView的问题:一个ListView的高度最多可以显示5个item,但是却有20条数据要显示,问最多会有多少个convertView会被复用?或者如在ListV ...
- 使用POI 导入excel
引言:最近一直在接触excel的问题,网页也有很多关于POI解析excel的资料,我也简单的整理了下,有不对地方的还望及时指正,渴望与大家交流并学习. public int importExcel(F ...
- Asp.Net Identity 2.0 认证
转Asp.Net Identity 2.0 认证 一个星期前,也就是3月20日,微软发布了Asp.Net Identity 2.0 RTM.功能更加强大,也更加稳定.Identity这个东西现在版本还 ...
- IOS内存泄漏
1. . - (void)viewDidLoad { [superviewDidLoad]; self.view.frame=CGRectMake(, , , ); NSArray *title1=[ ...
- D0
刚到长乐就被机房里众大神的气场给压倒了 orz....... 然后默默的感觉到自己貌似已经有一个星期没有打题了...就各种忧伤.... 还是说一下今天的计划吧 嗯傍晚5.30-6.00 &&a ...
- 译文:User-agent的历史
这是一篇译文,译文出处在文章底部贴出.由于技术水平,英语水平,翻译水平有限,请各路大侠多多指正,谢谢,提高你也提高我:) 几个礼拜之前,我谈论了特征检测和浏览器检测.这篇帖子提到了一点点嗅探U ...
- Django 中的 WSGI
Django 源码小剖: Django 中的 WSGI 2013-09-06 22:31 by 捣乱小子, 334 阅读, 0 评论, 收藏, 编辑 Django 其内部已经自带了一个方便本地测试的小 ...