Advanced Webscraping Features in C
HttpIdentity Özelliği
Bazı web sitesi sistemleri, içeriği görüntülemek için kullanıcının giriş yapmasını gerektirir; Bu durumda, 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)
IronWebScraper'deki en etkileyici ve güçlü özelliklerden biri, binlerce benzersiz kullanıcı kimliği ve/veya tarayıcı motorunu kullanarak birden fazla giriş oturumu kullanarak web sitelerini aldatma veya kazıma 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
Web sitelerinin sizi engellemesini önlemek için farklı davranışlar sağlayan birçok özelliğiniz var.
Bu özelliklerden bazıları şunları içerir:
NetworkDomain: Kullanıcı kimlik doğrulaması için kullanılacak ağ etki alanı. Windows, NTLM, Kerberos, Linux, BSD ve Mac OS X ağlarını destekler.NetworkUsernameveNetworkPasswordile birlikte kullanılmalıdır.NetworkUsername: Kullanıcı kimlik doğrulaması için kullanılacak network/http kullanıcı adı. HTTP, Windows ağları, NTLM, Kerberos, Linux ağları, BSD ağları ve Mac OS ağlarını destekler.NetworkPassword: Kullanıcı kimlik doğrulaması için kullanılacak network/http şifresi. HTTP, Windows ağları, NTLM, Kerberos, Linux ağları, BSD ağları ve Mac OS ağlarını destekler.Proxy: Proxy ayarlarını yapmak için.UserAgent: Bir tarayıcı motoru ayarlamak için (ör. Chrome masaüstü, Chrome mobil, Chrome tablet, IE ve Firefox vb.).HttpRequestHeaders: Bu kimlikle kullanılacak özel başlık değerleri için, bir sözlük nesnesiDictionary<string, string>kabul eder.UseCookies: Çerezleri etkinleştir/devre dışı bırak.
IronWebScraper, kazıyıcıyı rastgele kimlikler kullanarak çalıştırır. Sayfayı ayrıştırmak için belirli bir kimlik kullanmamız gerekirse, 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
Web Önbellek Özelliğini Etkinleştirme
Bu özellik, istenilen sayfaların önbelleğe alınması için kullanılır. Kod güncellenirken geliştiricilerin gerekli sayfaları yeniden kullanmak için önbelleğe almasını sağlamak amacıyla geliştirme ve test aşamalarında sıklıkla kullanılır. Web kazıyıcınızı yeniden başlattıktan sonra canlı web sitesine her seferinde bağlanmadan kodunuzu önbellekteki sayfalarda çalıştırmanızı sağlar (eylem-tekrar).
Bunu 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))
Önbelleğe alınmış verilerinizi çalışma dizini altındaki 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
IronWebScraper ayrıca, Start(CrawlID) kullanarak motorun başlatma işlem adını ayarlayarak, kodun yeniden başlatılmasından sonra motorunuzun kazımaya devam etmesini 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
Yürütme isteği ve yanıtı, çalışma dizini içindeki SavedState klasörüne kaydedilecektir.
Throttle Ayarı
Her domain için minimum ve maksimum bağlantı sayıları 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
Throttle özellikleri
MaxHttpConnectionLimitİzin verilen toplam açık HTTP istek sayısı (iş parçacıkları)RateLimitPerHostBelirli bir domain veya IP adresine yapılan istekler arasında minimum nazik gecikme veya duraklama (milisaniye cinsinden)OpenConnectionLimitPerHostHer ana bilgisayar adı için izin verilen eşzamanlı HTTP istek sayısı (iş parçacıkları)ThrottleModeWebScraper'ı yalnızca ana bilgisayar adları ile değil, aynı zamanda sunucu IP adresleri ile de akıllıca sınırlayın (throttle). Birden fazla kazınmış domainin aynı makinede barındırıldığı durumlarda nazik davranılır.
IronWebScraper ile Başlayın
Bugün IronWebScraper ile projenizde ücretsiz bir deneme ile başlayın.
Sıkça Sorulan Sorular
C#'ta kullanıcıları giriş gerektiren web sitelerinde nasıl doğrularım?
IronWebScraper'daki HttpIdentity özelliğini kullanarak, NetworkDomain, NetworkUsername, ve NetworkPassword gibi özellikleri ayarlayarak kullanıcıları doğrulama yapabilirsiniz.
Geliştirme sırasında web önbelleği kullanmanın faydası nedir?
Web önbelleği özelliği, özellikle geliştirme ve test aşamalarında, tekrar canlı web sitelerine bağlanmamayı sağladığı için, talep edilen sayfaları yeniden kullanım için önbelleğe almanıza olanak tanır, bu da zaman ve kaynak tasarrufu sağlar.
Web kazımada birden fazla oturum açma işlemini nasıl yönetirim?
IronWebScraper, binlerce benzersiz kullanıcı kimlik bilgisi ve tarayıcı motoru kullanılarak birden çok oturum açma işlemini simüle etmeye izin verir, bu da web sitelerinin kazıyıcıyı tespit edip engellemesini önlemeye yardımcı olur.
Web kazımada gelişmiş kısıtlama seçenekleri nelerdir?
IronWebScraper, ana makine adları ve IP adreslerine dayalı isteği akıllıca yöneten bir ThrottleMode ayarı sunar, bu da ortak barındırma ortamları ile saygılı bir etkileşimin sağlanmasını güvence altına alır.
IronWebScraper ile bir proxy nasıl kullanırım?
Bir proxy'yi kullanmak için, bir proxy dizisi tanımlayın ve IronWebScraper'deki HttpIdentity örnekleri ile ilişkilendirerek taleplerin farklı IP adresleri üzerinden yönlendirilmesine ve anonimlik ile erişim kontrolüne izin verin.
IronWebScraper sunucu aşırı yüklenmesini önlemek için istek gecikmelerini nasıl işler?
IronWebScraper'daki RateLimitPerHost ayarı, belirli bir alan adı veya IP adresine yönelik istekler arasındaki minimum gecikmeyi belirleyerek, istekleri yayarak sunucu aşırı yüklenmesini önlemeye yardımcı olur.
Web kazıma bir kesintiden sonra sürdürülebilir mi?
Evet, IronWebScraper, yürütme durumunu kaydeden ve son kaydedilen noktadan devam eden Start(CrawlID) yöntemini kullanarak bir kesintiden sonra kazımayı sürdürebilir.
Bir web kazıyıcıda eşzamanlı HTTP bağlantılarının sayısını nasıl kontrol ederim?
IronWebScraper'da, sunucu yükünü ve kaynakları yönetmek için izin verilen toplam açık HTTP istek sayısını kontrol etmek için MaxHttpConnectionLimit özelliğini ayarlayabilirsiniz.
Web kazıma faaliyetlerini kaydetmek için hangi seçenekler mevcuttur?
IronWebScraper, ayrıntılı analiz ve kazıma işlemleri sırasında hata ayıklama için kapsamlı günlüğe kaydetme sağlayan LoggingLevel özelliğini kullanarak günlüğe kaydetme seviyesini ayarlamanıza izin verir.

