WebページのHTMLを取得してファイルに書き出すサンプル

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string outputHtml = @"C:\tmp\yahoo.html";
            StreamWriter writer = new StreamWriter(outputHtml);

            WebClient client = new WebClient();
            string str = client.DownloadString("http://yahoo.com");
            writer.Write(str);

        }
    }
}

上記のサンプルで、YahooのWebページをHTMLまるごと取得して、C:\tmp\yahoo.htmlに書き出すことができる。

とりあえず

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です