C#의 고급 웹 스크래핑 기능

Curtis Chau
Curtis Chau
업데이트됨: 2026년 5월 9일

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);

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\";

    // 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);
}

웹사이트가 당신을 차단하지 않도록 여러 가지 프로퍼티를 제공하여 다른 동작을 할 수 있습니다.

이러한 속성 중 일부는 다음과 같습니다.

  • NetworkDomain: 사용자 인증에 사용할 네트워크 도메인입니다. Windows, NTLM, Kerberos, Linux, BSD 및 Mac OS X 네트워크를 지원합니다. NetworkUsername 및 NetworkPassword와 함께 사용해야 합니다.
  • NetworkUsername: 사용자 인증에 사용할 네트워크/http 사용자 이름입니다. HTTP, Windows 네트워크, NTLM, Kerberos, Linux 네트워크, BSD 네트워크 및 Mac OS를 지원합니다.
  • NetworkPassword: 사용자 인증에 사용할 네트워크/http 비밀번호입니다. HTTP, Windows 네트워크, NTLM, Kerberos, Linux 네트워크, BSD 네트워크 및 Mac OS를 지원합니다.
  • Proxy: 프록시 설정을 지정합니다.
  • UserAgent: 브라우저 엔진 설정 (예: Chrome desktop, Chrome mobile, Chrome tablet, IE, Firefox 등).
  • HttpRequestHeaders: 이 ID와 함께 사용할 사용자 정의 헤더 값을 위해, 사전 객체 Dictionary<string, string>를 허용합니다.
  • UseCookies: 쿠키 사용을 활성화/비활성화합니다.

IronWebScraper는 임의의 ID를 사용하여 스크래퍼를 실행합니다. 페이지를 파싱할 때 특정 식별자를 사용하도록 지정해야 하는 경우, 다음과 같이 할 수 있습니다.

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);
}

웹 캐시 기능을 활성화하세요

이 기능은 요청된 페이지를 캐시하는 데 사용됩니다. 이는 개발 및 테스트 단계에서 자주 사용되며, 개발자가 코드 업데이트 후 재사용할 수 있도록 필요한 페이지를 캐시할 수 있게 해줍니다. 이를 통해 웹 스크래퍼를 다시 시작한 후에도 매번 실제 웹사이트에 연결할 필요 없이 캐시된 페이지에서 코드를 실행할 수 있습니다(액션 리플레이).

당신은 Init() 메서드에서 사용할 수 있습니다:

// 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);
}

IronWebScraper는 엔진 시작 프로세스 이름을 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");
}

실행 요청과 응답은 작업 디렉토리의 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);
}

스로틀링 속성

  • MaxHttpConnectionLimit 허용된 총 HTTP 요청 수(스레드)
  • RateLimitPerHost 특정 도메인 또는 IP 주소에 대한 요청 간 최소한의 지연 시간(밀리초)
  • OpenConnectionLimitPerHost 호스트 이름당 허용되는 동시 HTTP 요청(스레드) 수
  • ThrottleMode 웹 스크래퍼가 호스트 이름뿐만 아니라 호스트 서버의 IP 주소로도 요청 속도를 지능적으로 조절할 수 있도록 합니다. 이는 스크랩한 도메인이 여러 개 같은 컴퓨터에 호스팅되는 경우를 대비한 예의 있는 표현입니다.

IronWebScraper로 시작하세요

오늘 무료 체험으로 프로젝트에서 IronWebScraper 사용을 시작하십시오.

첫 번째 단계:
arrow pointer

자주 묻는 질문

IronWebScraper에서 HttpIdentity 기능을 사용하는 목적은 무엇입니까?

IronWebScraper의 HttpIdentity 기능은 웹 스크래핑을 위해 다른 사용자 자격 증명 및 브라우저 엔진을 가장할 수 있도록 하여 여러 로그인 세션을 시뮬레이트함으로써 콘텐츠 액세스 제한을 우회하는 데 도움을 줍니다.

IronWebScraper에서 웹 캐싱을 어떻게 활성화할 수 있습니까?

'EnableWebCache()' 메서드를 사용하여 IronWebScraper에서 웹 캐싱을 활성화할 수 있습니다. 이는 개발자가 요청한 페이지를 캐싱하여, 특히 개발 및 테스트 단계에서 웹사이트에 반복적으로 연결할 필요 없이 재사용할 수 있도록 해줍니다.

IronWebScraper에서 제한을 활성화하는 이점은 무엇입니까?

IronWebScraper에서 제한을 활성화하면 도메인에 대한 연결 수와 속도를 관리하여 짧은 시간에 너무 많은 요청을 보내 차단될 가능성을 줄이는 데 도움이 됩니다. 요청을 시간이 지남에 따라 분산시킴으로써 공손하고 효율적인 스크래핑 프로세스를 보장합니다.

과정이 다시 시작되면 IronWebScraper가 계속해서 스크래핑할 수 있습니까?

네, IronWebScraper는 'Start(CrawlID)' 명령어를 사용하여 현재 상태를 저장함으로써 다시 시작 후 스크래핑 프로세스를 지속할 수 있습니다.

HttpIdentity에서 'UseCookies' 속성을 설정하는 용도는 무엇입니까?

HttpIdentity의 'UseCookies' 속성은 웹 스크래핑 세션 동안 IronWebScraper가 쿠키를 관리할 수 있게 하여, 요청 간에 상태를 유지하고 세션 데이터에 기반한 웹 사이트의 특정 제한을 우회할 수 있게 합니다.

웹 스크래핑에서 새로운 HttpIdentity 객체는 어떤 기능을 제공합니까?

IronWebScraper의 HttpIdentity 객체는 사용자 에이전트, 프록시 및 인증 자격 증명을 제어할 수 있게 하여, 다양한 시나리오에 맞춘 웹 콘텐츠 접근 및 사용자 행동을 모방할 수 있는 정교한 옵션을 제공합니다.

'RateLimitPerHost' 속성은 웹 스크래핑에 어떻게 도움이 됩니까?

'RateLimitPerHost' 속성은 동일한 도메인으로의 출력 요청 사이에 최소 지연을 보장하여 스크래퍼가 서버를 과부하시키지 않도록 하여 IP 차단의 위험을 줄이는 데 도움이 됩니다.

단일 스크래핑 작업에서 여러 HttpIdentity 인스턴스를 사용하는 이점은 무엇입니까?

여러 HttpIdentity 인스턴스를 사용하면 IronWebScraper가 요청에 대해 다른 정체성을 순환하도록 하여 여러 자격 증명과 브라우저 엔진에 걸쳐 부하를 분산할 수 있어 감지를 피하고 스크래핑 작업의 성공률을 높일 수 있습니다.

IronWebScraper에서 'WorkingDirectory'를 설정하는 것이 왜 중요합니까?

IronWebScraper에서 'WorkingDirectory'를 설정하면 출력 파일, 캐시된 데이터 및 상태 정보가 저장될 위치를 지정합니다. 데이터 조직과 스크래퍼가 작업 전체 동안 자원을 올바르게 접근하고 저장하는 데 매우 중요합니다.

IronWebScraper가 계속해서 라이브 웹사이트에 연결하지 않고 작업할 수 있습니까?

네, IronWebScraper는 웹 캐시 기능을 사용하여 라이브 웹사이트에 반복적으로 연결하지 않고 캐시된 페이지에서 작업을 수행할 수 있어 더 빠른 테스트 및 개발 주기를 용이하게 합니다.

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

더 읽기

시작할 준비 되셨나요?

NuGet 다운로드 수 150,502버전:2026.11방금 출시