Advanced Webscraping Features in C#
HttpIdentity 機能
一部のウェブサイトシステムでは、コンテンツを表示するためにユーザーがログインしている必要があります; この場合は、HttpIdentityを使用できます。 設定方法は次の通りです:
// Create a new instance of HttpIdentity
HttpIdentity id = new HttpIdentity();
// Set the network username and password for authentication
id.NetworkUsername = "username";
id.NetworkPassword = "pwd";
// Add the identity to the collection of identities
Identities.Add(id);' Create a new instance of HttpIdentity
Dim id As New HttpIdentity()
' Set the network username and password for authentication
id.NetworkUsername = "username"
id.NetworkPassword = "pwd"
' Add the identity to the collection of identities
Identities.Add(id)IronWebScraper の最も印象的で強力な機能の1つは、何千ものユニークなユーザー資格情報やブラウザエンジンを使用して、複数のログインセッションを通じてウェブサイトをスプーフィングまたはスクレイピングする能力です。
public override void Init()
{
// Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey";
// Set the logging level to capture all logs
this.LoggingLevel = WebScraper.LogLevel.All;
// Assign the working directory for the output files
this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
// Define an array of proxies
var proxies = "IP-Proxy1:8080,IP-Proxy2:8081".Split(',');
// Iterate over common Chrome desktop user agents
foreach (var UA in IronWebScraper.CommonUserAgents.ChromeDesktopUserAgents)
{
// Iterate over the proxies
foreach (var proxy in proxies)
{
// Add a new HTTP identity with specific user agent and proxy
Identities.Add(new HttpIdentity()
{
UserAgent = UA,
UseCookies = true,
Proxy = proxy
});
}
}
// Make an initial request to the website with a parse method
this.Request("http://www.Website.com", Parse);
}Public Overrides Sub Init()
' Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey"
' Set the logging level to capture all logs
Me.LoggingLevel = WebScraper.LogLevel.All
' Assign the working directory for the output files
Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
' Define an array of proxies
Dim proxies = "IP-Proxy1:8080,IP-Proxy2:8081".Split(","c)
' Iterate over common Chrome desktop user agents
For Each UA In IronWebScraper.CommonUserAgents.ChromeDesktopUserAgents
' Iterate over the proxies
For Each proxy In proxies
' Add a new HTTP identity with specific user agent and proxy
Identities.Add(New HttpIdentity() With {
.UserAgent = UA,
.UseCookies = True,
.Proxy = proxy
})
Next
Next
' Make an initial request to the website with a parse method
Me.Request("http://www.Website.com", AddressOf Parse)
End Sub異なる動作を提供し、ウェブサイトがブロックするのを防ぐための複数のプロパティがあります。
これらのプロパティには以下が含まれます:
NetworkDomain: ユーザー認証に使用するネットワークドメイン。 Windows、NTLM、Kerberos、Linux、BSD、および Mac OS X ネットワークをサポートしています。NetworkPasswordと共に使用する必要があります。NetworkUsername: ユーザー認証に使用するネットワーク/httpのユーザー名。 HTTP、Windows ネットワーク、NTLM、Kerberos、Linux ネットワーク、BSD ネットワーク、および Mac OS をサポートしています。NetworkPassword: ユーザー認証に使用するネットワーク/httpのパスワード。 HTTP、Windows ネットワーク、NTLM、Kerberos、Linux ネットワーク、BSD ネットワーク、および Mac OS をサポートしています。Proxy: プロキシ設定を設定するため。UserAgent: ブラウザエンジンを設定するため(例: Chromeデスクトップ、Chromeモバイル、Chromeタブレット、IE、Firefoxなど)。HttpRequestHeaders: このアイデンティティで使用されるカスタムヘッダー値のために、辞書オブジェクトDictionary<string, string>を受け入れます。UseCookies: クッキーの使用を有効/無効にします。
IronWebScraper はランダムなアイデンティティでスクレイパーを実行します。 特定のアイデンティティを指定してページを解析する必要がある場合、以下を行うことができます:
public override void Init()
{
// Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey";
// Set the logging level to capture all logs
this.LoggingLevel = WebScraper.LogLevel.All;
// Assign the working directory for the output files
this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
// Create a new instance of HttpIdentity
HttpIdentity identity = new HttpIdentity();
// Set the network username and password for authentication
identity.NetworkUsername = "username";
identity.NetworkPassword = "pwd";
// Add the identity to the collection of identities
Identities.Add(identity);
// Make a request to the website with the specified identity
this.Request("http://www.Website.com", Parse, identity);
}Public Overrides Sub Init()
' Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey"
' Set the logging level to capture all logs
Me.LoggingLevel = WebScraper.LogLevel.All
' Assign the working directory for the output files
Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
' Create a new instance of HttpIdentity
Dim identity As New HttpIdentity()
' Set the network username and password for authentication
identity.NetworkUsername = "username"
identity.NetworkPassword = "pwd"
' Add the identity to the collection of identities
Identities.Add(identity)
' Make a request to the website with the specified identity
Me.Request("http://www.Website.com", AddressOf Parse, identity)
End Subウェブキャッシュ機能の有効化
この機能は要求されたページをキャッシュするために使用されます。 開発とテストの段階でしばしば使用され、開発者がコードを更新した後に必要なページを再利用できるようにキャッシュします。 これにより、ウェブスクレイパーを再起動した後、常にライブウェブサイトに接続する必要なく、キャッシュされたページ上でコードを実行できます(アクションリプレイ)。
それをInit()メソッドで使用できます。
// Enable web cache without an expiration time
EnableWebCache();
// OR enable web cache with a specified expiration time
EnableWebCache(new TimeSpan(1, 30, 30));' Enable web cache without an expiration time
EnableWebCache()
' OR enable web cache with a specified expiration time
EnableWebCache(New TimeSpan(1, 30, 30))キャッシュされたデータは、作業ディレクトリ内のWebCacheフォルダに保存されます。
public override void Init()
{
// Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey";
// Set the logging level to capture all logs
this.LoggingLevel = WebScraper.LogLevel.All;
// Assign the working directory for the output files
this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
// Enable web cache with a specific expiration time of 1 hour, 30 minutes, and 30 seconds
EnableWebCache(new TimeSpan(1, 30, 30));
// Make an initial request to the website with a parse method
this.Request("http://www.Website.com", Parse);
}Public Overrides Sub Init()
' Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey"
' Set the logging level to capture all logs
Me.LoggingLevel = WebScraper.LogLevel.All
' Assign the working directory for the output files
Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
' Enable web cache with a specific expiration time of 1 hour, 30 minutes, and 30 seconds
EnableWebCache(New TimeSpan(1, 30, 30))
' Make an initial request to the website with a parse method
Me.Request("http://www.Website.com", Parse)
End SubIronWebScraperには、エンジンの開始プロセス名をStart(CrawlID)を使用して設定し、コードの再起動後もスクレイピングを続行するための機能もあります。
static void Main(string[] args)
{
// Create an object from the Scraper class
EngineScraper scrape = new EngineScraper();
// Start the scraping process with the specified crawl ID
scrape.Start("enginestate");
}Sub Main(ByVal args As String())
' Create an object from the Scraper class
Dim scrape As New EngineScraper()
' Start the scraping process with the specified crawl ID
scrape.Start("enginestate")
End Sub実行リクエストとレスポンスは作業ディレクトリ内のSavedStateフォルダに保存されます。
スロットリング
ドメインごとの最小および最大接続数および接続速度を制御できます。
public override void Init()
{
// Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey";
// Set the logging level to capture all logs
this.LoggingLevel = WebScraper.LogLevel.All;
// Assign the working directory for the output files
this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
// Set the total number of allowed open HTTP requests (threads)
this.MaxHttpConnectionLimit = 80;
// Set minimum polite delay (pause) between requests to a given domain or IP address
this.RateLimitPerHost = TimeSpan.FromMilliseconds(50);
// Set the allowed number of concurrent HTTP requests (threads) per hostname or IP address
this.OpenConnectionLimitPerHost = 25;
// Do not obey the robots.txt files
this.ObeyRobotsDotTxt = false;
// Makes the WebScraper intelligently throttle requests not only by hostname, but also by host servers' IP addresses
this.ThrottleMode = Throttle.ByDomainHostName;
// Make an initial request to the website with a parse method
this.Request("https://www.Website.com", Parse);
}Public Overrides Sub Init()
' Set the license key for IronWebScraper
License.LicenseKey = "LicenseKey"
' Set the logging level to capture all logs
Me.LoggingLevel = WebScraper.LogLevel.All
' Assign the working directory for the output files
Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
' Set the total number of allowed open HTTP requests (threads)
Me.MaxHttpConnectionLimit = 80
' Set minimum polite delay (pause) between requests to a given domain or IP address
Me.RateLimitPerHost = TimeSpan.FromMilliseconds(50)
' Set the allowed number of concurrent HTTP requests (threads) per hostname or IP address
Me.OpenConnectionLimitPerHost = 25
' Do not obey the robots.txt files
Me.ObeyRobotsDotTxt = False
' Makes the WebScraper intelligently throttle requests not only by hostname, but also by host servers' IP addresses
Me.ThrottleMode = Throttle.ByDomainHostName
' Make an initial request to the website with a parse method
Me.Request("https://www.Website.com", AddressOf Parse)
End Subスロットリングプロパティ
MaxHttpConnectionLimit許可されるオープンされた HTTP リクエスト(スレッド)の総数RateLimitPerHostドメインまたは IP アドレスに対するリクエスト間の最小の丁寧な遅延または一時停止(ミリ秒単位)OpenConnectionLimitPerHostホスト名ごとに許可される同時 HTTP リクエスト(スレッド)の数ThrottleModeWebScraper がホスト名だけでなく、ホストサーバーの IP アドレスによっても賢くリクエストを制限するようにします。 これは、同じマシンにホストされている複数のスクレイプされたドメインの場合には丁寧です。
IronWebScraperで始めましょう
Start using IronWebScraper in your project today with a free trial.
よくある質問
C# でログインを要求する Web サイトのユーザーをどのように認証できますか?
IronWebScraper の HttpIdentity 機能を利用して、NetworkDomain、NetworkUsername、および NetworkPassword などのプロパティを設定することでユーザーを認証できます。
開発中に Web キャッシュを使用する利点は何ですか?
Web キャッシュ機能を使用すると、要求されたページを再利用のためにキャッシュでき、特に開発およびテストフェーズ中に反復接続を避けて時間とリソースを節約できます。
Web スクレイピングで複数のログインセッションを管理する方法は?
IronWebScraper は、クラウドエンジンとともに、何千ものユニークなユーザー認証情報を使用して複数のログインセッションを模倣できるため、Web サイトから検出またはブロックされることを防ぎます。
Web スクレイピングにおける高度なスロットリングオプションは何ですか?
IronWebScraper は、ホスト名と IP アドレスに基づいて要求スロットリングをインテリジェントに管理する ThrottleMode 設定を提供しており、共有ホスティング環境との礼儀正しいやり取りを確保します。
IronWebScraper とプロキシをどのように使用しますか?
プロキシを使用するには、プロキシの配列を定義し、IronWebScraper の HttpIdentity インスタンスと関連付け、要求を異なる IP アドレス経由でルーティングして匿名性とアクセス制御を可能にします。
IronWebScraper はサーバーの過負荷を防ぐために要求の遅延をどのように処理しますか?
IronWebScraper の RateLimitPerHost 設定は、特定のドメインまたは IP アドレスへの要求ごとに最小遅延を指定し、要求を間隔をあけることでサーバーの過負荷を防ぎます。
Web スクレイピングが中断された場合、再開できますか?
はい、IronWebScraper は Start(CrawlID) メソッドを使用して再開でき、中断前の最後の状態から再開します。
Web スクレイパーでの同時 HTTP 接続の数をどのように制御しますか?
IronWebScraper では MaxHttpConnectionLimit プロパティを設定して、許可されるオープン HTTP リクエストの合計数を制御し、サーバー負荷とリソースを管理します。
Web スクレイピング活動のログを記録するためのオプションは何ですか?
IronWebScraperでは、LoggingLevelプロパティを使用してロギングレベルを設定でき、スクレイピング操作中の詳細分析とトラブルシューティングのための包括的なロギングを有効にします。
Can IronWebScraper work without connecting to a live website constantly?
Yes, IronWebScraper can work by utilizing its web cache feature, which allows it to perform actions on cached pages without repeatedly connecting to the live website, thus facilitating faster testing and development cycles.

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。