Created
June 3, 2014 13:01
-
-
Save EsProgram/8a3f714d2c4a5d10673f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Threading.Tasks; | |
using System.Web; | |
namespace CSharpConsole | |
{ | |
class ページ取得 | |
{ | |
static void Main(string[] args) | |
{ | |
WebClient wc = new WebClient(); | |
Byte[] content = wc.DownloadData("http://esprogram.github.io/index.html"); | |
String s = Encoding.ASCII.GetString(content); | |
Match encodeType = Regex.Match(s, @"<meta\s+[^>]*charset\s*=\s*([-_\w]+)", RegexOptions.IgnoreCase); | |
String e = encodeType.Success ? encodeType.Groups[1].Value : "shift_jis"; | |
Encoding contentEncoding = Encoding.GetEncoding(e); | |
Console.WriteLine(contentEncoding.GetString(content)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment