Skip to content

Demonstrates a website parsing capabilities via such libraries as HtmlAgilityPack.

License

Notifications You must be signed in to change notification settings

zanybaka/AvitoSearch

Repository files navigation

Avito Search

This repository stores the code demonstrating a website parsing capabilities via such libraries as HtmlAgilityPack.

What's inside?

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.

How does it work?

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

How to use Avito.Search library?

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?

2020

References

Disclaimer

About

Demonstrates a website parsing capabilities via such libraries as HtmlAgilityPack.

Topics

Resources

License

Stars

Watchers

Forks

Languages