Skip to content

Instantly share code, notes, and snippets.

@EsProgram
Created June 3, 2014 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EsProgram/8a3f714d2c4a5d10673f to your computer and use it in GitHub Desktop.
Save EsProgram/8a3f714d2c4a5d10673f to your computer and use it in GitHub Desktop.
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