【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/ 在罗老师的<算法竞赛 入门到进阶>总看到了 ...
随机推荐
- leetcode第四题--Add Two Numbers
Problem: You are given two linked lists representing two non-negative numbers. The digits are stored ...
- Vs2010中水晶报表引用及打包
原文:Vs2010中水晶报表引用及打包 转自:http://yunhaifeiwu.iteye.com/blog/1172283 Vs2010中水晶报表引用 在sap官网中下载支持vs 2010中的水 ...
- LinQ—扩展方法
概述 本节主要解说扩展方法,涉及LinQ的详细知识不多. 扩展方法的描写叙述 .net framework为编程人员提供了非常多的类,非常多的方法,可是,不论.net framework在类中为我们提 ...
- windows系统SVN和apache的下载和安装
原文:windows系统SVN和apache的下载和安装 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://ejb3.blogbus.com/logs/107443052. ...
- postal邮件发送(三):以附件形式显示图片
前言 上篇提到如果邮件中有图片的话,可以使用 @Html.EmbedImage("~/Content/postal.png") 这种方式,但是经过测试发现,在outlook中如果有 ...
- Mysql彻底卸载
-----本文摘自:http://www.heiqu.com/show-64764-1.html 1.控制面板里的增加删除程序内进行删除 2.删除MySQL文件夹下的my.ini文件,如果备份好,可以 ...
- Object instanceof Function和Function instanceof Object
首先需要确定的是,instanceof是根据原型链来判断是否为某引用类型的实例.所以需要明白Object和Function之间的关系,以下为引用某博客的图片,阐述了javascript对象体系的关系 ...
- java 权限 部分截图
下载地址:http://download.csdn.net/detail/heyehuang/5857263
- JS菜单条智能定位效果
JS仿淘宝详情页菜单条智能定位效果 2014-01-15 15:40 by 龙恩0707, 1366 阅读, 9 评论, 收藏, 编辑 类似于淘宝详情页菜单条智能定位 对于每个人来说并不陌生!如下截图 ...
- iOS基础 - Copy
copy和mutableCopy 一个对象使用copy或mutableCopy方法可以创建对象的副本 copy – 需要先实现NSCoppying协议,创建的是不可变副本(如NSString.NSAr ...