C# ile Gelişmiş Web Kazıma Özellikleri
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, 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
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)' 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
Next
' Make an initial request to the website with a parse method
Me.Request("http://www.Website.com", AddressOf Parse)
End SubPublic 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 SubWeb 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ğ 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 ağ/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 ağ/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ı belirlemek için.UserAgent: Bir tarayıcı motoru (örneğin, Chrome masaüstü, Chrome mobil, Chrome tablet, IE ve Firefox, vb.) ayarlamak için.HttpRequestHeaders: Bu kimlik ile kullanılacak özel başlık değerleri için, bir sözlük nesnesiDictionary<string, string>kabul eder.UseCookies: Çerez kullanımı etkinleştirme/devre dışı bırakma.
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", AddressOf Parse, identity)
End SubPublic 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 SubWeb Ö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).
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))' 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 klasörünün 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 SubPublic 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 ayrıca, Start(CrawlID) kullanarak motor başlangıç işlem adını ayarlayarak kod yeniden başlatıldıktan sonra kazıma işlemine devam etmenizi sağlayan özelliklere de 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");
}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 SubSub 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 SubYürütme isteği ve yanıtı, çalışma dizini içinde 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", AddressOf Parse)
End SubPublic 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 SubThrottle ö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
IronWebScraper'u projenizde kullanmaya bugün ücretsiz deneme sürümüyle başlayın.
Sıkça Sorulan Sorular
IronWebScraper'da HttpIdentity özelliğini kullanmanın amacı nedir?
IronWebScraper'daki HttpIdentity özelliği, kullanıcıların web kazıma için farklı kullanıcı kimlik bilgilerini ve tarayıcı motorlarını taklit etmelerine olanak tanır, böylece birden fazla oturum açma seansını simüle ederek içerik erişimi kısıtlamalarını aşmada yardımcı olur.
IronWebScraper'da web önbellekleme nasıl etkinleştirilir?
IronWebScraper'da web önbellekleme, 'EnableWebCache()' yöntemi kullanılarak etkinleştirilebilir. Bu, geliştiricilerin talep edilen sayfaları önbelleğe almasına olanak tanır ve özellikle geliştirme ve test aşamalarında bu sayfalar, web sitesine sürekli bağlanmaya gerek kalmadan yeniden kullanılabilir.
IronWebScraper'da hız sınırlamasını etkinleştirmenin avantajı nedir?
IronWebScraper'da hız sınırlamasını etkinleştirmek, bir zaman diliminde çok sayıda talep yapmaktan dolayı engellenme olasılığını azaltarak etki alanlarına yapılan bağlantıların sayısını ve hızını yönetmeye yardımcı olur. Talepleri zaman içinde dağıtarak nazik ve etkili bir kazıma sürecini sağlar.
IronWebScraper, süreç yeniden başlatılırsa kazımaya devam edebilir mi?
Evet, IronWebScraper, geçerli durumu 'Start(CrawlID)' komutunu kullanarak kaydederek işlemler yeniden başlatıldıktan sonra kazıma işlemlerine devam edebilir ve böylece kaldığı yerden devam edebilir.
HttpIdentity'de 'UseCookies' özelliğini ayarlamanın amacı nedir?
HttpIdentity'deki 'UseCookies' özelliği, IronWebScraper'ın web kazıma oturumları sırasında çerezleri yönetmesine olanak tanır ve bu da istekler arasında durumu koruyarak belirli web siteleri tarafından oturum verilerine bağlı olarak konulan bazı kısıtlamaları aşma potansiyeline sahip olmasını sağlar.
Yeni HttpIdentity nesneleri web kazımada hangi işlevleri sağlar?
IronWebScraper'deki HttpIdentity nesneleri, kullanıcı ajanlarını, proxy'leri ve kimlik doğrulama kimlik bilgilerini kontrol etmenize olanak tanır, böylece kullanıcı davranışını taklit etmek ve farklı senaryolara göre web içeriğine erişmek için ileri düzey seçenekler sunar.
'RateLimitPerHost' özelliği web kazımada nasıl yardımcı olur?
'RateLimitPerHost' özelliği, aynı etki alanına yönelik gönderilen talepler arasında minimum bir gecikmeyi garanti altına alarak kazıyıcının sunucuyu aşırı yüklemesini önler ve böylece IP engellemeleri riskini azaltır.
Tek bir kazıma görevinde birden fazla HttpIdentity örneği kullanmanın faydaları nelerdir?
Birden fazla HttpIdentity örneği kullanmak, IronWebScraper'ın isteklere yönelik farklı kimlikleri döngüsel olarak kullanmasına olanak tanır, böylece çeşitli kimlik bilgileri ve tarayıcı motorları arasında yükü dağıtarak tespit edilmekten kaçınabilir ve kazıma görevlerinin başarı oranını artırabilir.
IronWebScraper'da 'WorkingDirectory' belirlemek neden önemlidir?
IronWebScraper'da 'WorkingDirectory'yi ayarlamak, çıktı dosyalarının, önbelleğe alınmış verilerin ve durum bilgilerinin nerede depolanacağını belirtir. Verilerin düzenlenmesi ve kazıyıcının işletim sırasında kaynaklara doğru şekilde erişip kaydedebilmesi için önemlidir.
IronWebScraper, canlı bir web sitesine sürekli bağlanmadan çalışabilir mi?
Evet, IronWebScraper, önbellek özelliğini kullanarak önbelleğe alınmış sayfalarda işlemler gerçekleştirebilir, böylece canlı web sitesine sürekli bağlanmaya gerek kalmadan hızlandırılmış test ve geliştirme döngüleri sağlayabilir.
Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapılandırılmış, görsel olarak çekici kılavuzlar oluşturmayı seviyor.