Files
NScrapy/NScrapy.Spider/Spider.cs

35 lines
888 B
C#

using NScrapy.Infra;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace NScrapy.Spider
{
public abstract class Spider:ISpider
{
public List<string> URLs { get; set; }
public List<ISpiderMiddleware> Middlewares { get ; set; }
public Spider()
{
NScrapyContext.CurrentContext.CurrentSpider = this;
}
public virtual void StartRequests()
{
foreach (var url in this.URLs)
{
HttpRequest request = new HttpRequest()
{
URL = url,
RequestSpider = this
};
NScrapyContext.CurrentContext.CurrentScheduler.SendRequestToReceiver(request);
}
}
public abstract void ResponseHandler(IResponse response);
}
}