高度なWebスクレイピング機能

This article was translated from English: Does it need improvement?
Translated
View the article in English

 用 C# NuGet ライブラリ

でインストール NuGet

Install-Package IronWebScraper
または
Java PDF JAR(ジャバPDF JAR)

ダウンロード DLL (ディーエルエル)

DLLをダウンロード

プロジェクトに手動でインストールする

 用 C# NuGet ライブラリ

でインストール NuGet

Install-Package IronWebScraper
または
Java PDF JAR(ジャバPDF JAR)

ダウンロード DLL (ディーエルエル)

DLLをダウンロード

プロジェクトに手動でインストールする

今日からプロジェクトでIronPDFを使い始めましょう。無料のトライアルをお試しください。

最初のステップ:
green arrow pointer

チェックアウト IronWebscraper オン Nuget 迅速なインストールと展開のために。8百万以上のダウンロード数により、をC#で変革しています。

 用 C# NuGet ライブラリ nuget.org/packages/IronWebScraper/
Install-Package IronWebScraper

インストールを検討してください IronWebscraper DLL 直接。ダウンロードして、プロジェクトまたはGACの形式で手動でインストールしてください。 webscraperIronWebScraper.zip

プロジェクトに手動でインストールする

DLLをダウンロード

HttpIdentity 機能

ウェブサイトのシステムによっては、コンテンツを閲覧するためにログインが必要なものもあります; この場合、HttpIdentity: - を使用します。

HttpIdentity id = new HttpIdentity();
id.NetworkUsername = "username";
id.NetworkPassword = "pwd";
Identities.Add(id); 
HttpIdentity id = new HttpIdentity();
id.NetworkUsername = "username";
id.NetworkPassword = "pwd";
Identities.Add(id); 
Dim id As New HttpIdentity()
id.NetworkUsername = "username"
id.NetworkPassword = "pwd"
Identities.Add(id)
VB   C#

アイアンウェブスクレイパー(IronWebScraper)の最も印象的で強力な機能のひとつは、何千ものユニークな(アイアンウェブスクレイパー(IronWebScraper))を使用できることである。 (ユーザーの認証情報および/またはブラウザエンジン) マルチ・ログイン・セッションを使用してウェブサイトを詐称またはスクレイピングする。

public override void Init()
{
    License.LicenseKey = " LicenseKey ";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    var proxies = "IP-Proxy1: 8080,IP-Proxy2: 8081".Split(',');
    foreach (var UA in IronWebScraper.CommonUserAgents.ChromeDesktopUserAgents)
    {
        foreach (var proxy in proxies)
        {
            Identities.Add(new HttpIdentity()
            {
                UserAgent = UA,
                UseCookies = true,
                Proxy = proxy
            });
        }
    }
    this.Request("http://www.Website.com", Parse);
}
public override void Init()
{
    License.LicenseKey = " LicenseKey ";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    var proxies = "IP-Proxy1: 8080,IP-Proxy2: 8081".Split(',');
    foreach (var UA in IronWebScraper.CommonUserAgents.ChromeDesktopUserAgents)
    {
        foreach (var proxy in proxies)
        {
            Identities.Add(new HttpIdentity()
            {
                UserAgent = UA,
                UseCookies = true,
                Proxy = proxy
            });
        }
    }
    this.Request("http://www.Website.com", Parse);
}
Public Overrides Sub Init()
	License.LicenseKey = " LicenseKey "
	Me.LoggingLevel = WebScraper.LogLevel.All
	Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
	Dim proxies = "IP-Proxy1: 8080,IP-Proxy2: 8081".Split(","c)
	For Each UA In IronWebScraper.CommonUserAgents.ChromeDesktopUserAgents
		For Each proxy In proxies
			Identities.Add(New HttpIdentity() With {
				.UserAgent = UA,
				.UseCookies = True,
				.Proxy = proxy
			})
		Next proxy
	Next UA
	Me.Request("http://www.Website.com", Parse)
End Sub
VB   C#

複数のプロパティで異なる動作をさせることで、ウェブサイトからのブロックを防ぐことができます。

その一部を紹介しよう: -

  • NetworkDomain :ユーザー認証に使用するネットワーク・ドメイン。 Windows、NTLM、Keroberos、Linux、BSD、Mac OS Xネットワークをサポートします。 と併用する必要がある。 (ネットワークユーザー名とネットワークパスワード)
  • ネットワークユーザー名 : ユーザー認証に使用するネットワーク/httpユーザー名。 Http、Windowsネットワーク、NTLM、Kerberos、Linuxネットワーク、BSDネットワーク、Mac OSをサポートします。
  • NetworkPassword : ユーザー認証に使用するネットワーク/httpパスワード。 Http、Windowsネットワーク、NTLM、Keroberos、Linuxネットワーク、BSDネットワークおよびMac OSをサポートしています。
  • **プロキシ設定
  • UserAgent : ブラウザエンジンを設定します。 (クロームデスクトップ、クロームモバイル、クロームタブレット、IE、Firefoxなど。)
  • HttpRequestHeaders : この ID で使用されるカスタムヘッダ値で、辞書オブジェクトを受け入れます。(辞書 <string, string)

  • UseCookies:クッキーの使用を有効/無効にする

    アイアンウェブスクレイパーはランダムなIDを使ってスクレイパーを実行する。 ページの解析に特定のIDの使用を指定する必要がある場合は、そうすることができる。

public override void Init()
{
    License.LicenseKey = " LicenseKey ";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    HttpIdentity identity = new HttpIdentity();
    identity.NetworkUsername = "username";
    identity.NetworkPassword = "pwd";
    Identities.Add(id);
    this.Request("http://www.Website.com", Parse, identity);
}
public override void Init()
{
    License.LicenseKey = " LicenseKey ";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    HttpIdentity identity = new HttpIdentity();
    identity.NetworkUsername = "username";
    identity.NetworkPassword = "pwd";
    Identities.Add(id);
    this.Request("http://www.Website.com", Parse, identity);
}
Public Overrides Sub Init()
	License.LicenseKey = " LicenseKey "
	Me.LoggingLevel = WebScraper.LogLevel.All
	Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
	Dim identity As New HttpIdentity()
	identity.NetworkUsername = "username"
	identity.NetworkPassword = "pwd"
	Identities.Add(id)
	Me.Request("http://www.Website.com", Parse, identity)
End Sub
VB   C#

ウェブキャッシュ機能を有効にする

この機能は、リクエストされたページをキャッシュするために使用されます。 開発やテストの段階でよく使われる; 開発者がコードを更新した後に、必要なページをキャッシュして再利用できるようにする。 これにより、ウェブスクレーパーを再起動した後、キャッシュされたページでコードを実行することができ、毎回ライブのウェブサイトに接続する必要がなくなります。 (アクションリプレイ).

イニシャル() 方法

WebCacheを有効にする();`

OR

WebCacheを有効にする(有効期限);`

キャッシュされたデータは、作業ディレクトリフォルダ下のWebCacheフォルダに保存されます。

public override void Init()
{
    License.LicenseKey = " LicenseKey ";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    EnableWebCache(new TimeSpan(1,30,30));
    this.Request("http://www.WebSite.com", Parse);
}
public override void Init()
{
    License.LicenseKey = " LicenseKey ";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    EnableWebCache(new TimeSpan(1,30,30));
    this.Request("http://www.WebSite.com", Parse);
}
Public Overrides Sub Init()
	License.LicenseKey = " LicenseKey "
	Me.LoggingLevel = WebScraper.LogLevel.All
	Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
	EnableWebCache(New TimeSpan(1,30,30))
	Me.Request("http://www.WebSite.com", Parse)
End Sub
VB   C#

IronWebscraperには、Start (アイアンウェブスクレイパー)を使ってエンジンのスタートプロセス名を設定することで、コードの再起動後にエンジンがスクレイピングを継続できるようにする機能もあります。(クロールID)

static void Main(string [] args)
{
    // Create Object From Scraper class
    EngineScraper scrape = new EngineScraper();
    // Start Scraping
    scrape.Start("enginestate");
}
static void Main(string [] args)
{
    // Create Object From Scraper class
    EngineScraper scrape = new EngineScraper();
    // Start Scraping
    scrape.Start("enginestate");
}
Shared Sub Main(ByVal args() As String)
	' Create Object From Scraper class
	Dim scrape As New EngineScraper()
	' Start Scraping
	scrape.Start("enginestate")
End Sub
VB   C#

実行リクエストとレスポンスは、作業ディレクトリ内のSavedStateフォルダに保存される。

スロットリング

ドメインごとに最小接続数、最大接続数、接続速度をコントロールすることができます。

public override void Init()
{
    License.LicenseKey = "LicenseKey";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    // Gets or sets the total number of allowed open HTTP requests (threads)
    this.MaxHttpConnectionLimit = 80;
    // Gets or sets minimum polite delay (pause)between request to a given domain or IP address.
    this.RateLimitPerHost = TimeSpan.FromMilliseconds(50);            
    //     Gets or sets the allowed number of concurrent HTTP requests (threads) per hostname
    //     or IP address. This helps protect hosts against too many requests.
    this.OpenConnectionLimitPerHost = 25;
    this.ObeyRobotsDotTxt = false;
    //     Makes the WebSraper intelligently throttle requests not only by hostname, but
    //     also by host servers' IP addresses. This is polite in-case multiple scraped domains
    //     are hosted on the same machine.
    this.ThrottleMode = Throttle.ByDomainHostName;
    this.Request("https://www.Website.com", Parse);
}
public override void Init()
{
    License.LicenseKey = "LicenseKey";
    this.LoggingLevel = WebScraper.LogLevel.All;
    this.WorkingDirectory = AppSetting.GetAppRoot() + @"\ShoppingSiteSample\Output\";
    // Gets or sets the total number of allowed open HTTP requests (threads)
    this.MaxHttpConnectionLimit = 80;
    // Gets or sets minimum polite delay (pause)between request to a given domain or IP address.
    this.RateLimitPerHost = TimeSpan.FromMilliseconds(50);            
    //     Gets or sets the allowed number of concurrent HTTP requests (threads) per hostname
    //     or IP address. This helps protect hosts against too many requests.
    this.OpenConnectionLimitPerHost = 25;
    this.ObeyRobotsDotTxt = false;
    //     Makes the WebSraper intelligently throttle requests not only by hostname, but
    //     also by host servers' IP addresses. This is polite in-case multiple scraped domains
    //     are hosted on the same machine.
    this.ThrottleMode = Throttle.ByDomainHostName;
    this.Request("https://www.Website.com", Parse);
}
Public Overrides Sub Init()
	License.LicenseKey = "LicenseKey"
	Me.LoggingLevel = WebScraper.LogLevel.All
	Me.WorkingDirectory = AppSetting.GetAppRoot() & "\ShoppingSiteSample\Output\"
	' Gets or sets the total number of allowed open HTTP requests (threads)
	Me.MaxHttpConnectionLimit = 80
	' Gets or sets minimum polite delay (pause)between request to a given domain or IP address.
	Me.RateLimitPerHost = TimeSpan.FromMilliseconds(50)
	'     Gets or sets the allowed number of concurrent HTTP requests (threads) per hostname
	'     or IP address. This helps protect hosts against too many requests.
	Me.OpenConnectionLimitPerHost = 25
	Me.ObeyRobotsDotTxt = False
	'     Makes the WebSraper intelligently throttle requests not only by hostname, but
	'     also by host servers' IP addresses. This is polite in-case multiple scraped domains
	'     are hosted on the same machine.
	Me.ThrottleMode = Throttle.ByDomainHostName
	Me.Request("https://www.Website.com", Parse)
End Sub
VB   C#

スロットル特性

  • MaxHttpConnectionLimit


    許可されたオープンHTTPリクエストの総数 (糸)

  • RateLimitPerHost


    最小限の丁寧なディレイまたはポーズ (ミリ秒で) 指定されたドメインまたはIPアドレスへのリクエスト間

  • *OpenConnectionLimitPerHost(オープン・コネクション・リミット・パー・ホスト)。


    同時HTTPリクエスト数 (糸)

  • **スロットルモード


    WebSraperは、ホスト名だけでなく、ホストサーバーのIPアドレスによってもインテリジェントにリクエストをスロットルするようになります。 これは、複数のスクレイピングされたドメインが同じマシン上でホストされている場合に役立つ。

.NETソフトウェアエンジニア .NETからPDFファイルを生成する最も効率的な方法の一つです。追加のAPIを学習する必要もなく、また複雑な設計システムを操作する必要もありません。

アーメッド・アブエルマグド

多国籍IT企業の.NETソフトウェアソリューションアーキテクト

Ahmedは経験豊富で認定を受けたMicrosoft Technologyスペシャリストであり、ITおよびソフトウェア開発の分野で10年以上の経験を持っています。彼はさまざまな企業で働いており、現在は多国籍IT企業のカントリーマネージャーを務めています。

アーメドは、自社の複数のプロジェクトでIronPDFとIronWebScraperを1年以上にわたり使用しています。