Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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