As for the title,the console program will show you a sample which can get the webpage-code.Enjoy it:)

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.IO;
  8. using System.Runtime.InteropServices; //dllimport relies on it
  9. namespace WebPageCode
  10. {
  11.  
  12. class Program
  13. {
  14.  
  15. [DllImport("kernel32.dll")]
  16. static extern uint GetTickCount();
  17.  
  18. static void addhead(ref string px) //add http head if necessary
  19. {
  20. if (px.Substring(, ).ToLower() != @"http://") px = @"http://" + px;
  21. }
  22.  
  23. static string getwebcode(string PageUrl,string proxy=""){
  24.  
  25. uint x = GetTickCount();
  26.  
  27. addhead(ref PageUrl); //webpage check
  28. WebClient wc = new WebClient();
  29. wc.Credentials = CredentialCache.DefaultCredentials;
  30.  
  31. proxy.Trim(); //proxy check
  32. if (proxy != "")
  33. {
  34. addhead(ref proxy);
  35. WebProxy wp = new WebProxy();
  36. wp.Address = new Uri(proxy);
  37. wc.Proxy = wp;
  38. }
  39.  
  40. Byte[] pageData = wc.DownloadData(PageUrl);
  41. x = GetTickCount() - x; //x means the time spent.
  42. return Encoding.UTF8.GetString(pageData);
  43.  
  44. }
  45.  
  46. static void Main(string[] args)
  47. {
  48. int i = , n = args.Length;
  49. string proxy = "";
  50. string page = "";
  51. while (i < n)
  52. {
  53. if (args[i] == "-proxy")
  54. {
  55. if (i<(n-)) proxy = args[++i];
  56. }
  57. if (args[i] == "-page")
  58. {
  59. if (i < (n - )) page = args[++i];
  60. }
  61. i++;
  62. }
  63. page.Trim(); proxy.Trim();
  64. if (page == "") return; //no webpage found
  65. string code;
  66. if (proxy == ""){
  67. code=getwebcode(page); //proxy found
  68. } else {
  69. code=getwebcode(page,proxy); //no proxy found
  70. }
  71.  
  72. Console.Write(code);
  73. Console.ReadKey();
  74. }
  75. }
  76. }

【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. 记第五届山东省ACM程序设计比赛——遗憾并非遗憾

    记第五届山东省ACM程序设计比赛 5月10日上午9点半左右,我们的队伍从学校出发,一个多小时后到达本次比赛的地点-哈尔滨工业大学. 报道,领材料,吃午饭,在哈工大的校园里逛了逛,去主楼的自习室歇息了一 ...

  2. Lucene.net入门学习

    Lucene.net入门学习(结合盘古分词)   Lucene简介 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全 ...

  3. 使用javaservice 将jboss 注册为服务

    近来做项目,需要jboss定期重新启动.不想再看到jboss启动那个黑洞洞的窗口,就想着把它注册为服务,然后在net start.恰好objectweb上有个open source的javaservi ...

  4. Java 感知Mysql存储过程变量数量

    在项目中,可能会遇到sybase 移植到 mysql的情况,因为sybase 支持存储过程的可变参数,而mysql不能支持,所以,在调用mysql的时候,需要感知存储过程到底有几个参数,来合理的配置参 ...

  5. ASP.NET MVC 缓存扩展 - Donut Caching

    项目介绍 ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code ...

  6. JAVA学习:多态

    多态:可以理解为事物存在的多种体现形态.   人:男人,女人 动物:猫,狗. 猫 x = new 猫(); 动物 x = new 猫()   1,多态的体现 父类的引用指向了自己的子类对象. 父类的引 ...

  7. sqlserver中数据的四种插入方式

    1.insert into stuInfo(name,stuId) values('李洁','19291727')insert into stuInfo(name,stuId) values('李康' ...

  8. 迁移Model元数据设置项

    .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序) 阅读目录: 1.需求背景介绍(Model元数据设置项应该与View绑定而非ViewModel) 1 ...

  9. iOS基础 - 史上最难游戏

    步骤一:隐藏状态栏 步骤二:屏幕适配 步骤三:设置窗口的根控制器为导航控制器,并且设置导航条和状态栏. 步骤四:搭建设置界面 步骤五:控制器连线 步骤六:搭建关卡控制器 加载pilst文件 创建关卡模 ...

  10. Binder机制,从Java到C (4. Parcel)

    1. 远程调用的数据传输 在远程的函數中,必然会需要传递一些数据,那这些数据是怎么传输的呢? 在IPC中,Proxy端的作用就是将一些参数打包,然后发送出去,下面是在Proxy端经常会遇见的调用远程方 ...