【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/ 在罗老师的<算法竞赛 入门到进阶>总看到了 ...
随机推荐
- openwrt构建过程探索
参考网站:http://wiki.openwrt.org/doc/howto/buildroot.exigence 需要下载必要的库文件,编译器等... 1 首先要获得openwrt的源码,参考ope ...
- 使用Oracle 9i工具管理数据库 - 初学者系列 - 学习者系列文章
前面介绍了Oracle 9i的安装,本文大概介绍下Oracle 9i提供的管理工具的使用. 1 打开数据库配置工具 2 下一步 3 下一步 4 下一步.这里输入数据库名和SID 5 下一步 6 下一步 ...
- javascript 日期对象(date)详解
Date 对象 Date 对象用于处理日期和时间. 创建 Date 对象的语法: var myDate=new Date(); 注释:Date 对象会自动把当前日期和时间保存为其初始值. 1.date ...
- 使用winform控件注意线程绘制界面冲突
在用.NET Framework框架的WinForm构建GUI程序界面时,如果要在控件的事件响应函数中改变控件的状态,例如:某个按钮上的文本原先叫“打开”,单击之后按钮上的文本显示“关闭”,初学者往往 ...
- Factovisors - PC110704
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10139.html 原创: 作者: ...
- Linq无聊练习系列2--select/distinct练习
void dataBindByWhere() { /**************select/distinct 练习*******************/ //获 ...
- 生成自己的Webapi帮助文档(二)
经过今天一上午的修改,已经有个基础的框架了,其它功能只能是在实际使用中发现一个修改一个了. 以下是生成的结果示例: 相比昨天,几个Model都有修改,这里就不一一贴代码了,放个代码包上来,有需要的自己 ...
- 7 MySQL存储过程和函数
目录: 1. 存储过程和函数概述2. 准备工作3. 存储过程操作4. 创建带参存储过程5. 查看存储过程 1. 存储过程和函数概述 MySQL的存储过程(stored procedure)和函数(st ...
- 自定义表单-jsonform
项目文件地址:https://github.com/powmedia/backbone-forms#editor-list DEOM:http://jsfiddle.net/evilcelery/dW ...
- 《cracking the coding intreview》——链表
前言 最近准备暑假回家回家修整一下,所以时间大部分用来完成项目上的工作,同时为了9月份的校招,晚上的时间我还在学习<cracking the coding intreview>,第二章链表 ...