This repository stores the code demonstrating a website parsing capabilities via such libraries as HtmlAgilityPack.
First of all it's Avito.Search library which allows you to get search results as easy as possible.
Also you can use Avito.UI.WinForms.Window application which demonstrates the functionality visually.
It's based on the public query syntax https://www.avito.ru/?bt=1&p=1&q=apple
A simple WebRequest is used to get the html content.
WebRequest request = WebRequest.Create(url);
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException)
...
Then it's being parsed via HtmlAgilityPack library.
HtmlDocument doc = new HtmlDocument();
doc.OptionFixNestedTags = true;
doc.LoadHtml(content);
For example, a link to the latest page can be found with the following code
doc.DocumentNode.SelectNodes("//a[@class='pagination-page']")?.LastOrDefault()
Once the library is referenced you can use it like in the example below
AvitoSettings settings = new AvitoSettings();
AvitoPageRequest request = new AvitoPageRequest(settings, "apple watch", searchInTitlesOnly: true);
AvitoPage page = new AvitoPage(settings, request);
Filter filter = new Filter
{
TitleContains = new[] { "apple", "watch" },
TitleDoesNotContain = new[] { "46m" },
DatesAfter = DateTime.Now.AddDays(-5),
MaxPrice = 20000,
MinPrice = 10000
};
List<WebSearchResult> results = page.GetResults(filter);
So, it can be easily integrated into any kind of applications like
- Desktop UI (WinForms, WPF)
- Web application (ASP.NET)
- Server-side application
- Bot (Telegram, etc.)
How does Avito.UI.WinForms.Window application look like?
- Icons for the demo application were downloaded from https://www.freeicons.io/
- HtmlAgilityPack library
- Krypton WinForms controls
- Developed for educational purposes only.
- Avito.ru website is used as an example.
- Don't forget to check https://www.avito.ru/info/polzovatelskoe_soglashenie if you are going to use it somehow