Advanced Webscraping Features in C

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

HttpIdentity Özelliği

Bazı web sitesi sistemlerinin içeriği görüntüleyebilmek için kullanıcının oturum açmasını gerektirmektedir; Bu durumda, bir HttpIdentity kullanabiliriz. İşte nasıl ayarlayabileceğiniz:

// 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
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)
$vbLabelText   $csharpLabel

IronWebScraper'daki en etkileyici ve güçlü özelliklerden biri, binlerce benzersiz kullanıcı kimliği ve/veya tarayıcı motorlarını kullanarak, çoklu oturum açma oturumları kullanarak web sitelerini taklit etme veya tarama yeteneğidir.

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 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 proxy
	Next UA

	' Make an initial request to the website with a parse method
	Me.Request("http://www.Website.com", Parse)
End Sub
$vbLabelText   $csharpLabel

Sizi engelleyen sitelerle baş edebilmeniz için farklı davranışlar veren birkaç özelliğiniz var.

Bu özelliklerden bazıları şunları içerir:

  • NetworkDomain: Kullanıcı kimlik doğrulaması için kullanılacak ağ alanı. Windows, NTLM, Kerberos, Linux, BSD ve Mac OS X ağlarını destekler. NetworkUsername ve NetworkPassword ile kullanılmalıdır.
  • NetworkUsername: Kullanıcı kimlik doğrulaması için kullanılacak ağ/http kullanıcı adı. HTTP, Windows ağlarını, NTLM, Kerberos, Linux ağlarını, BSD ağlarını ve Mac OS'u destekler.
  • NetworkPassword: Kullanıcı kimlik doğrulaması için kullanılacak ağ/http parolası. HTTP, Windows ağlarını, NTLM, Kerberos, Linux ağlarını, BSD ağlarını ve Mac OS'u destekler.
  • Proxy: Proxy ayarlarını ayarlamak için.
  • UserAgent: Bir tarayıcı motorunu ayarlamak için (örneğin, Chrome masaüstü, Chrome mobil, Chrome tablet, IE ve Firefox vb.).
  • HttpRequestHeaders: Bu kimlikle kullanılacak özel üst bilgi değerleri için bir sözlük nesnesi Dictionary<string, string> kabul eder.
  • UseCookies: Çerezlerin kullanılmasını etkinleştir/devre dışı bırak.

IronWebScraper, rasgele kimlikler kullanarak tarama yapar. Belirli bir kimliği ayarlayarak bir sayfayı çözümlememiz gerekiyorsa, bunu yapabiliriz:

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 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", Parse, identity)
End Sub
$vbLabelText   $csharpLabel

Web Önbellek Özelliğini Etkinleştir

Bu özellik istenen sayfaları önbelleğe almak için kullanılır. Geliştirme ve test aşamalarında sıkça kullanılır ve geliştiricilere kodu güncelledikten sonra tekrar kullanım için gerekli sayfaları önbelleğe almalarını sağlar. Web tarayıcınızı yeniden başlattıktan sonra önbelleğe alınmış sayfalarda kodunuzu çalıştırmanıza olanak tanır, her zaman canlı web sitesine bağlanmanıza gerek kalmadan (aksiyon-yeniden oynatma).

Onu Init() yönteminde kullanabilirsiniz:

// 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));
' Enable web cache without an expiration time
EnableWebCache()

' OR enable web cache with a specified expiration time
EnableWebCache(New TimeSpan(1, 30, 30))
$vbLabelText   $csharpLabel

Önbelleğe alınan verilerinizi çalışma dizini klasörünün altında WebCache klasörüne kaydedecektir.

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 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 Sub
$vbLabelText   $csharpLabel

IronWebScraper ayrıca, Start(CrawlID) kullanarak motor başlangıç süreci adını ayarlayarak kodu yeniden başlattığında web kazıma işlemine devam etmenizi sağlayan özelliklere sahiptir.

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");
}
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");
}
Shared 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
$vbLabelText   $csharpLabel

Çalıştırma isteği ve yanıtı, çalışma dizini içindeki SavedState klasörüne kaydedilecektir.

Kısıtlama

Her alan adı başına minimum ve maksimum bağlantı numaralarını ve bağlantı hızını kontrol edebiliriz.

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 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", Parse)
End Sub
$vbLabelText   $csharpLabel

Kısıtlama özellikleri

  • MaxHttpConnectionLimit
    Açık HTTP taleplerinin toplam izin verilen sayısı (iş parçacıkları)
  • RateLimitPerHost
    Belirli bir alan adına veya IP adresine yapılan istekler arasında, minimum nazik gecikme veya duraklama (milisaniye cinsinden)
  • OpenConnectionLimitPerHost
    Her ana bilgisayar adı başına eşzamanlı HTTP isteği (iş parçacıkları) için izin verilen sayısı
  • ThrottleMode
    WebTarayıcı yalnızca ana bilgisayar adına göre değil, aynı zamanda ana bilgisayar sunucularının IP adreslerine göre de istekleri zekice kısar. Aynı makinede barındırılan birden fazla kazılı alan adı durumunda bu naziktir.

IronWebscraper ile başlayın

!{--0100110001001001010000100101001001000001010100100101100101011111--}

Sıkça Sorulan Sorular

C#'ta oturum açmayı gerektiren web sitelerinde kullanıcıları nasıl kimlik doğrulayıp yetkilendirebilirim?

IronWebScraper'da HttpIdentity özelliğini kullanabilir ve kullanıcıları NetworkDomain, NetworkUsername, ve NetworkPassword gibi özellikleri kurarak kimlik doğrulaması yapabilirsiniz.

Geliştirme sırasında web önbelleği kullanmanın faydası nedir?

Web önbelleği özelliği, talep edilen sayfaları yeniden kullanmak için önbelleklemenize olanak tanır, bu da tekrarlanan bağlantılardan kaçınarak zaman ve kaynaklardan tasarruf sağlar, özellikle geliştirme ve test aşamalarında kullanışlıdır.

Web kazımada birden fazla giriş oturumunu nasıl yönetebilirim?

IronWebScraper, kazıcının tespit edilmesini ve engellenmesini önlemeye yardımcı olacak binlerce benzersiz kullanıcı kimlik bilgisi ve tarayıcı motoru kullanarak çoklu giriş oturumlarını simüle etmeye izin verir.

Web kazımada gelişmiş sınırlama seçenekleri nelerdir?

IronWebScraper, ev sahibi adlarına ve IP adreslerine dayalı talep sınırlamasını akıllıca yöneten bir ThrottleMode ayarı sunar, bu da paylaşılan barındırma ortamları ile saygılı etkileşimi sağlar.

IronWebScraper ile bir proxy nasıl kullanılır?

Bir proxy kullanmak için, bir proxy dizisi tanımlayın ve IronWebScraper'da HttpIdentity örnekleri ile ilişkilendirerek taleplerin farklı IP adresleri üzerinden yönlendirilmesini sağlayan anonimlik ve erişim kontrolü elde edersiniz.

IronWebScraper sunucu aşırı yüklenmesini önlemek için talep gecikmelerini nasıl ele alır?

IronWebScraper'de RateLimitPerHost ayarı, belirli bir alan adı veya IP adresine yapılan talepler arasında minimum gecikmeyi belirtir, talep sıklığını dengeli bir şekilde ayarlayarak sunucu aşırı yüklenmesini önlemeye yardımcı olur.

Bir kesintiden sonra web kazıma yeniden başlayabilir mi?

Evet, IronWebScraper, Start(CrawlID) yöntemini kullanarak bir kesintiden sonra kazımaya devam edebilir, bu da yürütme durumunu kaydeder ve son kaydedilen noktadan devam eder.

Bir web kazıyıcıda eşzamanlı HTTP bağlantılarının sayısını nasıl kontrol edebilirim?

IronWebScraper'da, genel olarak izin verilen açık HTTP taleplerinin toplam sayısını kontrol etmek için MaxHttpConnectionLimit özelliğini ayarlayarak sunucu yükünü ve kaynakları yönetebilirsiniz.

Web kazıma aktiviteleri için hangi kayıt seçenekleri mevcut?

IronWebScraper, ayrıntılı analiz ve kazıma işlemleri sırasında sorun giderme için kapsamlı bir kayıt seviyesi sağlayarak, LoggingLevel özelliğini ayarlamanıza izin verir.

Darrius Serrant
Tam Yığın Yazılım Mühendisi (WebOps)

Darrius Serrant, Miami Üniversitesi'nden Bilgisayar Bilimleri lisans derecesine sahiptir ve Iron Software'de Tam Yığın WebOps Pazarlama Mühendisi olarak çalışmaktadır. Küçük yaşlardan itibaren kodlamaya ilgi duyan Darrius, bilişimi hem gizemli hem de erişilebilir buldu ve onu yaratıcılık ve problem çö...

Daha Fazlasını Oku
Başlamaya Hazır mısınız?
Nuget İndirmeler 134,614 | Sürüm: 2026.4 just released
Still Scrolling Icon

Hala Kaydiriyor musunuz?

Hızlı bir kanit mi istiyorsunuz? PM > Install-Package IronWebScraper
bir örneği çalıştır hedef sitenizi yapılandırılmış veri haline getirin.