При добавлении System.Net появились новые предупреждения.
И ошибка. Но форуме Adot написал, пока тишина.
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(11,19) : error CS1729: Abot.Core.PageRequester не содержит конструктор, который принимает 0 аргументов
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(47,27) : warning CS0168: Переменная "ex" объявлена, но ни разу не использовалась
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(64,27) : warning CS0168: Переменная "ex" объявлена, но ни разу не использовалась
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(81,27) : warning CS0168: Переменная "ex" объявлена, но ни разу не использовалась
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(97,23) : warning CS0168: Переменная "ex" объявлена, но ни разу не использовалась
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(110,23) : warning CS0168: Переменная "ex" объявлена, но ни разу не использовалась
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(123,23) : warning CS0168: Переменная "ex" объявлена, но ни разу не использовалась
c:\Users\Pavel\AppData\Local\Temp\z0nw0vnz.0.cs(136,23) : warning CS0168: Переменная "ex" объявлена, но ни разу не использовалась
код получился вот таким:
using System;
using System.Runtime.InteropServices;
using Abot.Crawler;
using Abot.Poco;
using Abot.Core;
using System.Net;
namespace Elisy.NetBridge.Crawler
{
public class YourCustomPageRequester : PageRequester
{
protected override HttpWebRequest BuildRequestObject(Uri uri)
{
var request = base.BuildRequestObject(uri);
request.Proxy = new WebProxy("212.82.126.32:80");
return request;
}
}
public class Helper : IDisposable
{
object _form;
public IWebCrawler Crawler {get; set;}
public Helper(CrawlConfiguration crawlConfig, object form)
{
_form = form;
Crawler = new PoliteWebCrawler(crawlConfig, null, null, null, new YourCustomPageRequester(), null, null,null, null);
Crawler.PageCrawlStartingAsync += crawler_ProcessPageCrawlStarting;
Crawler.PageCrawlCompletedAsync += crawler_ProcessPageCrawlCompleted;
Crawler.PageCrawlDisallowedAsync += crawler_PageCrawlDisallowed;
Crawler.PageLinksCrawlDisallowedAsync += crawler_PageLinksCrawlDisallowed;
Crawler.ShouldDownloadPageContent((crawledPage, crawlContext) =>
{
CrawlDecision decision = new CrawlDecision { Allow = true };
try
{
object result = _form.GetType().InvokeMember("crawler_ShouldDownloadPageContent",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, _form, new object[] {decision, crawledPage, crawlContext });
return decision;
}
catch(Exception ex)
{
return decision;
}
});
Crawler.ShouldCrawlPage((pageToCrawl, crawlContext) =>
{
CrawlDecision decision = new CrawlDecision { Allow = true };
try
{
object result = _form.GetType().InvokeMember("crawler_ShouldCrawlPage",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, _form, new object[] {decision, pageToCrawl, crawlContext });
return decision;
}
catch(Exception ex)
{
return decision;
}
});
Crawler.ShouldCrawlPageLinks((crawledPage, crawlContext) =>
{
CrawlDecision decision = new CrawlDecision { Allow = true };
try
{
object result = _form.GetType().InvokeMember("crawler_ShouldCrawlPageLinks",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, _form, new object[] {decision, crawledPage, crawlContext });
return decision;
}
catch(Exception ex)
{
return decision;
}
});
}
void crawler_ProcessPageCrawlStarting(object sender, PageCrawlStartingArgs e)
{
try
{
object result = _form.GetType().InvokeMember("crawler_ProcessPageCrawlStarting",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, _form, new object[] { sender, e });
}
catch(Exception ex)
{
}
}
void crawler_ProcessPageCrawlCompleted(object sender, PageCrawlCompletedArgs e)
{
try
{
object result = _form.GetType().InvokeMember("crawler_ProcessPageCrawlCompleted",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, _form, new object[] { sender, e });
}
catch(Exception ex)
{
}
}
void crawler_PageLinksCrawlDisallowed(object sender, PageLinksCrawlDisallowedArgs e)
{
try
{
object result = _form.GetType().InvokeMember("crawler_PageLinksCrawlDisallowed",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, _form, new object[] { sender, e });
}
catch(Exception ex)
{
}
}
void crawler_PageCrawlDisallowed(object sender, PageCrawlDisallowedArgs e)
{
try
{
object result = _form.GetType().InvokeMember("crawler_PageCrawlDisallowed",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, _form, new object[] { sender, e });
}
catch(Exception ex)
{
}
}
public void Dispose()
{
if (_form != null)
Marshal.ReleaseComObject(_form);
}
}
}
Показать