IronWebScraper 方法 オンライン映画サイトのスクレイピング C#とIronWebScraperを使ってオンライン映画ウェブサイトをスクレイピングする カーティス・チャウ 更新日:6月 10, 2025 IronWebScraper をダウンロード NuGet ダウンロード DLL ダウンロード 無料トライアル LLM向けのコピー LLM向けのコピー LLM 用の Markdown としてページをコピーする ChatGPTで開く このページについてChatGPTに質問する ジェミニで開く このページについてGeminiに問い合わせる ジェミニで開く このページについてGeminiに問い合わせる 困惑の中で開く このページについてPerplexityに問い合わせる 共有する Facebook で共有 Xでシェア(Twitter) LinkedIn で共有 URLをコピー 記事をメールで送る This article was translated from English: Does it need improvement? Translated View the article in English 実際のウェブサイトから別の例を始めてみましょう。映画のウェブサイトをスクレイピングすることにします。 新しいクラスを追加し、"MovieScraper"と名付けましょう。 これからスクレイピングするサイトを見てみましょう。 これはウェブサイトで見られるホームページのHTMLの一部です。 <div id="movie-featured" class="movies-list movies-list-full tab-pane in fade active"> <div data-movie-id="20746" class="ml-item"> <a href="https://website.com/film/king-arthur-legend-of-the-sword-20746/"> <span class="mli-quality">CAM</span> <img data-original="https://img.gocdn.online/2017/05/16/poster/2116d6719c710eabe83b377463230fbe-king-arthur-legend-of-the-sword.jpg" class="lazy thumb mli-thumb" alt="King Arthur: Legend of the Sword" src="https://img.gocdn.online/2017/05/16/poster/2116d6719c710eabe83b377463230fbe-king-arthur-legend-of-the-sword.jpg" style="display: inline-block;"> <span class="mli-info"><h2>King Arthur: Legend of the Sword</h2></span> </a> </div> <div data-movie-id="20724" class="ml-item"> <a href="https://website.com/film/snatched-20724/"> <span class="mli-quality">CAM</span> <img data-original="https://img.gocdn.online/2017/05/16/poster/5ef66403dc331009bdb5aa37cfe819ba-snatched.jpg" class="lazy thumb mli-thumb" alt="Snatched" src="https://img.gocdn.online/2017/05/16/poster/5ef66403dc331009bdb5aa37cfe819ba-snatched.jpg" style="display: inline-block;"> <span class="mli-info"><h2>Snatched</h2></span> </a> </div> </div> <div id="movie-featured" class="movies-list movies-list-full tab-pane in fade active"> <div data-movie-id="20746" class="ml-item"> <a href="https://website.com/film/king-arthur-legend-of-the-sword-20746/"> <span class="mli-quality">CAM</span> <img data-original="https://img.gocdn.online/2017/05/16/poster/2116d6719c710eabe83b377463230fbe-king-arthur-legend-of-the-sword.jpg" class="lazy thumb mli-thumb" alt="King Arthur: Legend of the Sword" src="https://img.gocdn.online/2017/05/16/poster/2116d6719c710eabe83b377463230fbe-king-arthur-legend-of-the-sword.jpg" style="display: inline-block;"> <span class="mli-info"><h2>King Arthur: Legend of the Sword</h2></span> </a> </div> <div data-movie-id="20724" class="ml-item"> <a href="https://website.com/film/snatched-20724/"> <span class="mli-quality">CAM</span> <img data-original="https://img.gocdn.online/2017/05/16/poster/5ef66403dc331009bdb5aa37cfe819ba-snatched.jpg" class="lazy thumb mli-thumb" alt="Snatched" src="https://img.gocdn.online/2017/05/16/poster/5ef66403dc331009bdb5aa37cfe819ba-snatched.jpg" style="display: inline-block;"> <span class="mli-info"><h2>Snatched</h2></span> </a> </div> </div> HTML 見ての通り、映画ID、タイトル、詳細ページへのリンクがあります。 これらデータセットのスクレイピングを始めましょう。 public class MovieScraper : WebScraper { public override void Init() { // Initialize scraper settings License.LicenseKey = "LicenseKey"; this.LoggingLevel = WebScraper.LogLevel.All; this.WorkingDirectory = AppSetting.GetAppRoot() + @"\MovieSample\Output\"; // Request homepage content for scraping this.Request("www.website.com", Parse); } public override void Parse(Response response) { // Iterate over each movie div within the featured movie section foreach (var div in response.Css("#movie-featured > div")) { if (div.Attributes["class"] != "clearfix") { var movieId = Convert.ToInt32(div.GetAttribute("data-movie-id")); var link = div.Css("a")[0]; var movieTitle = link.TextContentClean; // Scrape and store movie data as key-value pairs Scrape(new ScrapedData() { { "MovieId", movieId }, { "MovieTitle", movieTitle } }, "Movie.Jsonl"); } } } } public class MovieScraper : WebScraper { public override void Init() { // Initialize scraper settings License.LicenseKey = "LicenseKey"; this.LoggingLevel = WebScraper.LogLevel.All; this.WorkingDirectory = AppSetting.GetAppRoot() + @"\MovieSample\Output\"; // Request homepage content for scraping this.Request("www.website.com", Parse); } public override void Parse(Response response) { // Iterate over each movie div within the featured movie section foreach (var div in response.Css("#movie-featured > div")) { if (div.Attributes["class"] != "clearfix") { var movieId = Convert.ToInt32(div.GetAttribute("data-movie-id")); var link = div.Css("a")[0]; var movieTitle = link.TextContentClean; // Scrape and store movie data as key-value pairs Scrape(new ScrapedData() { { "MovieId", movieId }, { "MovieTitle", movieTitle } }, "Movie.Jsonl"); } } } } Public Class MovieScraper Inherits WebScraper Public Overrides Sub Init() ' Initialize scraper settings License.LicenseKey = "LicenseKey" Me.LoggingLevel = WebScraper.LogLevel.All Me.WorkingDirectory = AppSetting.GetAppRoot() & "\MovieSample\Output\" ' Request homepage content for scraping Me.Request("www.website.com", AddressOf Parse) End Sub Public Overrides Sub Parse(ByVal response As Response) ' Iterate over each movie div within the featured movie section For Each div In response.Css("#movie-featured > div") If div.Attributes("class") <> "clearfix" Then Dim movieId = Convert.ToInt32(div.GetAttribute("data-movie-id")) Dim link = div.Css("a")(0) Dim movieTitle = link.TextContentClean ' Scrape and store movie data as key-value pairs Scrape(New ScrapedData() From { { "MovieId", movieId }, { "MovieTitle", movieTitle } }, "Movie.Jsonl") End If Next div End Sub End Class $vbLabelText $csharpLabel このコードの新しい点は何ですか? 作業ディレクトリプロパティは、スクレイピングしたデータと関連ファイル全てのメイン作業ディレクトリを設定するために使用されます。 もっとやりましょう。 スクレイピングしたデータをフォーマットされたオブジェクトとして保持する型付きオブジェクトを構築する必要がある場合はどうしますか? フォーマットされたデータを保持するMovieクラスを実装しましょう。 public class Movie { public int Id { get; set; } public string Title { get; set; } public string URL { get; set; } } public class Movie { public int Id { get; set; } public string Title { get; set; } public string URL { get; set; } } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel コードを更新します。 public class MovieScraper : WebScraper { public override void Init() { // Initialize scraper settings License.LicenseKey = "LicenseKey"; this.LoggingLevel = WebScraper.LogLevel.All; this.WorkingDirectory = AppSetting.GetAppRoot() + @"\MovieSample\Output\"; // Request homepage content for scraping this.Request("https://website.com/", Parse); } public override void Parse(Response response) { // Iterate over each movie div within the featured movie section foreach (var div in response.Css("#movie-featured > div")) { if (div.Attributes["class"] != "clearfix") { var movie = new Movie { Id = Convert.ToInt32(div.GetAttribute("data-movie-id")) }; var link = div.Css("a")[0]; movie.Title = link.TextContentClean; movie.URL = link.Attributes["href"]; // Scrape and store movie object Scrape(movie, "Movie.Jsonl"); } } } } public class MovieScraper : WebScraper { public override void Init() { // Initialize scraper settings License.LicenseKey = "LicenseKey"; this.LoggingLevel = WebScraper.LogLevel.All; this.WorkingDirectory = AppSetting.GetAppRoot() + @"\MovieSample\Output\"; // Request homepage content for scraping this.Request("https://website.com/", Parse); } public override void Parse(Response response) { // Iterate over each movie div within the featured movie section foreach (var div in response.Css("#movie-featured > div")) { if (div.Attributes["class"] != "clearfix") { var movie = new Movie { Id = Convert.ToInt32(div.GetAttribute("data-movie-id")) }; var link = div.Css("a")[0]; movie.Title = link.TextContentClean; movie.URL = link.Attributes["href"]; // Scrape and store movie object Scrape(movie, "Movie.Jsonl"); } } } } Public Class MovieScraper Inherits WebScraper Public Overrides Sub Init() ' Initialize scraper settings License.LicenseKey = "LicenseKey" Me.LoggingLevel = WebScraper.LogLevel.All Me.WorkingDirectory = AppSetting.GetAppRoot() & "\MovieSample\Output\" ' Request homepage content for scraping Me.Request("https://website.com/", AddressOf Parse) End Sub Public Overrides Sub Parse(ByVal response As Response) ' Iterate over each movie div within the featured movie section For Each div In response.Css("#movie-featured > div") If div.Attributes("class") <> "clearfix" Then Dim movie As New Movie With {.Id = Convert.ToInt32(div.GetAttribute("data-movie-id"))} Dim link = div.Css("a")(0) movie.Title = link.TextContentClean movie.URL = link.Attributes("href") ' Scrape and store movie object Scrape(movie, "Movie.Jsonl") End If Next div End Sub End Class $vbLabelText $csharpLabel 新しい点は何ですか? スクレイピングしたデータを保持するMovieクラスを実装しました。 映画オブジェクトをScrapeメソッドに渡し、このメソッドはフォーマットを理解し、以下の画像に示される定義された方法で保存します。 もっと詳細なページのスクレイピングを始めましょう。 映画ページはこのように見えます: <div class="mvi-content"> <div class="thumb mvic-thumb" style="background-image: url(https://img.gocdn.online/2017/04/28/poster/5a08e94ba02118f22dc30f298c603210-guardians-of-the-galaxy-vol-2.jpg);"></div> <div class="mvic-desc"> <h3>Guardians of the Galaxy Vol. 2</h3> <div class="desc"> Set to the backdrop of Awesome Mixtape #2, Marvel's Guardians of the Galaxy Vol. 2 continues the team's adventures as they travel throughout the cosmos to help Peter Quill learn more about his true parentage. </div> <div class="mvic-info"> <div class="mvici-left"> <p> <strong>Genre: </strong> <a href="https://Domain/genre/action/" title="Action">Action</a>, <a href="https://Domain/genre/adventure/" title="Adventure">Adventure</a>, <a href="https://Domain/genre/sci-fi/" title="Sci-Fi">Sci-Fi</a> </p> <p> <strong>Actor: </strong> <a target="_blank" href="https://Domain/actor/chris-pratt" title="Chris Pratt">Chris Pratt</a>, <a target="_blank" href="https://Domain/actor/-zoe-saldana" title="Zoe Saldana">Zoe Saldana</a>, <a target="_blank" href="https://Domain/actor/-dave-bautista-" title="Dave Bautista">Dave Bautista</a> </p> <p> <strong>Director: </strong> <a href="#" title="James Gunn">James Gunn</a> </p> <p> <strong>Country: </strong> <a href="https://Domain/country/us" title="United States">United States</a> </p> </div> <div class="mvici-right"> <p><strong>Duration:</strong> 136 min</p> <p><strong>Quality:</strong> <span class="quality">CAM</span></p> <p><strong>Release:</strong> 2017</p> <p><strong>IMDb:</strong> 8.3</p> </div> <div class="clearfix"></div> </div> <div class="clearfix"></div> </div> <div class="clearfix"></div> </div> <div class="mvi-content"> <div class="thumb mvic-thumb" style="background-image: url(https://img.gocdn.online/2017/04/28/poster/5a08e94ba02118f22dc30f298c603210-guardians-of-the-galaxy-vol-2.jpg);"></div> <div class="mvic-desc"> <h3>Guardians of the Galaxy Vol. 2</h3> <div class="desc"> Set to the backdrop of Awesome Mixtape #2, Marvel's Guardians of the Galaxy Vol. 2 continues the team's adventures as they travel throughout the cosmos to help Peter Quill learn more about his true parentage. </div> <div class="mvic-info"> <div class="mvici-left"> <p> <strong>Genre: </strong> <a href="https://Domain/genre/action/" title="Action">Action</a>, <a href="https://Domain/genre/adventure/" title="Adventure">Adventure</a>, <a href="https://Domain/genre/sci-fi/" title="Sci-Fi">Sci-Fi</a> </p> <p> <strong>Actor: </strong> <a target="_blank" href="https://Domain/actor/chris-pratt" title="Chris Pratt">Chris Pratt</a>, <a target="_blank" href="https://Domain/actor/-zoe-saldana" title="Zoe Saldana">Zoe Saldana</a>, <a target="_blank" href="https://Domain/actor/-dave-bautista-" title="Dave Bautista">Dave Bautista</a> </p> <p> <strong>Director: </strong> <a href="#" title="James Gunn">James Gunn</a> </p> <p> <strong>Country: </strong> <a href="https://Domain/country/us" title="United States">United States</a> </p> </div> <div class="mvici-right"> <p><strong>Duration:</strong> 136 min</p> <p><strong>Quality:</strong> <span class="quality">CAM</span></p> <p><strong>Release:</strong> 2017</p> <p><strong>IMDb:</strong> 8.3</p> </div> <div class="clearfix"></div> </div> <div class="clearfix"></div> </div> <div class="clearfix"></div> </div> HTML Movieクラスに新しいプロパティ(説明、ジャンル、俳優、監督、国、上映時間、IMDbスコア)を追加できますが、サンプルでは(説明、ジャンル、俳優)のみ使用します。 using System.Collections.Generic; public class Movie { public int Id { get; set; } public string Title { get; set; } public string URL { get; set; } public string Description { get; set; } public List<string> Genre { get; set; } public List<string> Actor { get; set; } } using System.Collections.Generic; public class Movie { public int Id { get; set; } public string Title { get; set; } public string URL { get; set; } public string Description { get; set; } public List<string> Genre { get; set; } public List<string> Actor { get; set; } } Imports System.Collections.Generic Public Class Movie Public Property Id() As Integer Public Property Title() As String Public Property URL() As String Public Property Description() As String Public Property Genre() As List(Of String) Public Property Actor() As List(Of String) End Class $vbLabelText $csharpLabel 詳細ページに移動してスクレイピングします。 IronWebScraperを使用すると、スクレイプ関数にさまざまなページフォーマットをスクレイピングする機能を追加できます。 ここで見ることができるように: public class MovieScraper : WebScraper { public override void Init() { // Initialize scraper settings License.LicenseKey = "LicenseKey"; this.LoggingLevel = WebScraper.LogLevel.All; this.WorkingDirectory = AppSetting.GetAppRoot() + @"\MovieSample\Output\"; // Request homepage content for scraping this.Request("https://domain/", Parse); } public override void Parse(Response response) { // Iterate over each movie div within the featured movie section foreach (var div in response.Css("#movie-featured > div")) { if (div.Attributes["class"] != "clearfix") { var movie = new Movie { Id = Convert.ToInt32(div.GetAttribute("data-movie-id")) }; var link = div.Css("a")[0]; movie.Title = link.TextContentClean; movie.URL = link.Attributes["href"]; // Request detailed page this.Request(movie.URL, ParseDetails, new MetaData() { { "movie", movie } }); } } } public void ParseDetails(Response response) { // Retrieve movie object from metadata var movie = response.MetaData.Get<Movie>("movie"); var div = response.Css("div.mvic-desc")[0]; // Extract description movie.Description = div.Css("div.desc")[0].TextContentClean; // Extract genres movie.Genre = new List<string>(); // Initialize genre list foreach(var genre in div.Css("div > p > a")) { movie.Genre.Add(genre.TextContentClean); } // Extract actors movie.Actor = new List<string>(); // Initialize actor list foreach (var actor in div.Css("div > p:nth-child(2) > a")) { movie.Actor.Add(actor.TextContentClean); } // Scrape and store detailed movie data Scrape(movie, "Movie.Jsonl"); } } public class MovieScraper : WebScraper { public override void Init() { // Initialize scraper settings License.LicenseKey = "LicenseKey"; this.LoggingLevel = WebScraper.LogLevel.All; this.WorkingDirectory = AppSetting.GetAppRoot() + @"\MovieSample\Output\"; // Request homepage content for scraping this.Request("https://domain/", Parse); } public override void Parse(Response response) { // Iterate over each movie div within the featured movie section foreach (var div in response.Css("#movie-featured > div")) { if (div.Attributes["class"] != "clearfix") { var movie = new Movie { Id = Convert.ToInt32(div.GetAttribute("data-movie-id")) }; var link = div.Css("a")[0]; movie.Title = link.TextContentClean; movie.URL = link.Attributes["href"]; // Request detailed page this.Request(movie.URL, ParseDetails, new MetaData() { { "movie", movie } }); } } } public void ParseDetails(Response response) { // Retrieve movie object from metadata var movie = response.MetaData.Get<Movie>("movie"); var div = response.Css("div.mvic-desc")[0]; // Extract description movie.Description = div.Css("div.desc")[0].TextContentClean; // Extract genres movie.Genre = new List<string>(); // Initialize genre list foreach(var genre in div.Css("div > p > a")) { movie.Genre.Add(genre.TextContentClean); } // Extract actors movie.Actor = new List<string>(); // Initialize actor list foreach (var actor in div.Css("div > p:nth-child(2) > a")) { movie.Actor.Add(actor.TextContentClean); } // Scrape and store detailed movie data Scrape(movie, "Movie.Jsonl"); } } Public Class MovieScraper Inherits WebScraper Public Overrides Sub Init() ' Initialize scraper settings License.LicenseKey = "LicenseKey" Me.LoggingLevel = WebScraper.LogLevel.All Me.WorkingDirectory = AppSetting.GetAppRoot() & "\MovieSample\Output\" ' Request homepage content for scraping Me.Request("https://domain/", AddressOf Parse) End Sub Public Overrides Sub Parse(ByVal response As Response) ' Iterate over each movie div within the featured movie section For Each div In response.Css("#movie-featured > div") If div.Attributes("class") <> "clearfix" Then Dim movie As New Movie With {.Id = Convert.ToInt32(div.GetAttribute("data-movie-id"))} Dim link = div.Css("a")(0) movie.Title = link.TextContentClean movie.URL = link.Attributes("href") ' Request detailed page Me.Request(movie.URL, AddressOf ParseDetails, New MetaData() From { { "movie", movie } }) End If Next div End Sub Public Sub ParseDetails(ByVal response As Response) ' Retrieve movie object from metadata Dim movie = response.MetaData.Get(Of Movie)("movie") Dim div = response.Css("div.mvic-desc")(0) ' Extract description movie.Description = div.Css("div.desc")(0).TextContentClean ' Extract genres movie.Genre = New List(Of String)() ' Initialize genre list For Each genre In div.Css("div > p > a") movie.Genre.Add(genre.TextContentClean) Next genre ' Extract actors movie.Actor = New List(Of String)() ' Initialize actor list For Each actor In div.Css("div > p:nth-child(2) > a") movie.Actor.Add(actor.TextContentClean) Next actor ' Scrape and store detailed movie data Scrape(movie, "Movie.Jsonl") End Sub End Class $vbLabelText $csharpLabel 新しい点は何ですか? 詳細ページをスクレイピングするためのスクレイプ関数(例:ParseDetails)を追加できます。 ファイルを生成するScrape機能を新しい関数に移動しました。 IronWebScraperの機能(MetaData)を使用して、新しいスクレイプ関数に映画オブジェクトを渡しました。 ページをスクレイピングし、映画オブジェクトデータをファイルに保存しました。 よくある質問 オンライン映画サイトからデータをスクレイピングするにはどうしたらよいですか? IronWebScraperを使用してオンライン映画サイトからデータをスクレイピングすることができます。まず、スクレイパーの設定を行い、トップページのコンテンツを取得してデータを抽出する'MovieScraper'クラスを作成します。 ウェブスクレイピングにおける'Movie'クラスの機能は何ですか? IronWebScraperでは、'Movie'クラスは、Id、Title、URL、Description、Genre、Actorなどのプロパティを持つオブジェクトとしてスクレイピングされたデータを構造化して保存し、組織的なデータ処理を行うために使用されます。 詳細な映画情報をナビゲートして抽出する方法は? IronWebScraperを使用すると、'ParseDetails'関数を実装して詳細な映画ページにアクセスし、説明、ジャンル、俳優などの追加情報を抽出することができます。 ウェブスクレイピングにおける'MetaData'機能の役割は何ですか? IronWebScraperの'MetaData'機能は、映画オブジェクトを'ParseDetails'関数に渡してさらに処理するなど、スクレイピング関数間のデータ転送において重要です。 スクレイピング中の異なるページフォーマットをどのように処理しますか? IronWebScraperを使用すれば、さまざまなページフォーマットを管理し、幅広いデータを効率的に抽出するために複数のスクレイピング関数を作成できます。 IronWebScraperを使用して映画IDとタイトルをどのように抽出しますか? IronWebScraper内の注目映画セクションの各映画divを反復処理し、データ属性とテキストコンテンツにアクセスすることで映画IDとタイトルを抽出します。 スクレイパー設定におけるログの重要性は何ですか? IronWebScraperの'LoggingLevel'プロパティを使用することで、ログ出力の詳細度を設定し、スクレイピングプロセスを効果的に監視およびトラブルシューティングするのに役立ちます。 ウェブスクレイピングプロジェクトにおける作業ディレクトリの機能は何ですか? IronWebScraperの作業ディレクトリは、スクレイピングされたすべてのデータおよび関連ファイルを保存するために指定されており、データ管理プロセスを一元化します。 IronWebScraperを使用してデータ抽出タスクを自動化することはできますか? はい、IronWebScraperは、ユーザーがクラスやメソッドを作成してウェブページからデータを体系的にスクレイピングして保存することで、データ抽出タスクを自動化するように設計されています。 カーティス・チャウ 今すぐエンジニアリングチームとチャット テクニカルライター Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。 準備はできましたか? Nuget ダウンロード 125,527 | Version: 2025.11 リリース NuGet 無料版 総ダウンロード数: 125,527 ライセンスを見る