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

  1. 【JS】Advanced1:Object-Oriented Code

    Object-Oriented Code 1. var Person = function (name) { this.name = name; }; Person.prototype.say = f ...

  2. 【cocos2d-x】尝鲜 Cocos Code IDE(不断更新)

    Cocos Code IDE 是一个基于 Eclipse 的跨平台 IDE ,专门为 cocos2d lua & js 开发者准备,通过此工具.你能够方便的创建游戏project.编写而且调试 ...

  3. 【转】vscode: Visual Studio Code 常用快捷键

    原文链接:https://www.cnblogs.com/bindong/p/6045957.html vscode: Visual Studio Code 常用快捷键 主命令框 F1 或 Ctrl+ ...

  4. 【译】第5节---Code First约定

    原文:http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx 我们在上一节中已经看到了EF Code ...

  5. 【PowerDesigner】【9】禁止Name与Code同步

    问题:修改了某个字段的name,其code也跟着修改 步骤:Tools→General Options..→Dialog→取消勾选“Name to Code mirroring”复选框 参考博客: 1 ...

  6. 【题解】Popping Balls AtCoder Code Festival 2017 qual B E 组合计数

    蒟蒻__stdcall终于更新博客辣~ 一下午+一晚上=一道计数题QAQ 为什么计数题都这么玄学啊QAQ Prelude 题目链接:这里是传送门= ̄ω ̄= 下面我将分几个步骤讲一下这个题的做法,大家不 ...

  7. 【Leetcode】804. Unique Morse Code Words

    Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...

  8. 【微信】根据appid, secret, code获取用户基本信息

    function getUserInfo(){ $appid = "yourappid"; $secret = "yoursecret"; $code = $_ ...

  9. 【转载】Why Learning to Code is So Damn Hard By Erik Trautman

    原文网址:https://www.thinkful.com/blog/why-learning-to-code-is-so-damn-hard/ 在罗老师的<算法竞赛 入门到进阶>总看到了 ...

随机推荐

  1. ASP.NET MVC进阶

    ASP.NET MVC进阶 一.ASP.NET MVC中的AJAX应用 首先,在ASP.NET MVC中使用自带的ajax功能,必须要导入2个js文件(顺序不能颠倒): ASP.NET MVC提供了2 ...

  2. socket计划——一个简单的例子

    从一个简单易用TCP样品开始socket计划,的基本过程例如下列: server                                                  client +++ ...

  3. AngularJS+requireJS项目的目录结构设想

    AngularJS+requireJS项目的目录结构设想 准备用AngularJS + require.js 作为新项目的底层框架,以下目录结果只是一个初步设想: /default    放页面,不过 ...

  4. php中使用随机数

    <?phpsession_start();$s = array("a","b","c","d","e&q ...

  5. dbcp的配置

    tomcat的 配置,进入conf->context.xml <Resource name="mysql"     auth="Container" ...

  6. 【推荐】30个Matlab视频教程合集(含GUI视频教程)下载

    自己收集别人网盘上存的资源,分享一下[点击文件名可得到下载地址]        Matlab 7.8 基础视频教程 实例1 数据传递和多窗口编程_avi.zip 205.11 MB   Matlab ...

  7. Effective C++(12) 复制对象时要复制每一个成员

    问题聚焦: 负责拷贝的两个操作:拷贝构造函数和重载赋值操作符. 一句话总结,确保被拷贝对象的所有成员变量都做一份拷贝. Demo   void logCall(const std::string&am ...

  8. 状态机图statechart diagram

    [UML]UML系列——状态机图statechart diagram 系列文章 [UML]UML系列——用例图Use Case [UML]UML系列——用例图中的各种关系(include.extend ...

  9. ASP.NET Session丢失问题原因及解决方案

    正常操作情况下会有ASP.NET Session丢失的情况出现.因为程序是在不停的被操作,排除Session超时的可能.另外,Session超时时间被设定成60分钟,不会这么快就超时的. ASP.NE ...

  10. Object-c学习之路十一(NSDate和反射)

    挺简单啥也不说了直接上代码(NSDate和反射) // // main.m // NSNumberAndNSValue // // Created by WildCat on 13-7-26. // ...