-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrapping.cs
More file actions
executable file
·51 lines (40 loc) · 1.59 KB
/
Copy pathscrapping.cs
File metadata and controls
executable file
·51 lines (40 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/home/adavidoaiei/dotnet/dotnet run
#:package HtmlAgilityPack@1.12.1
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using HtmlAgilityPack;
var httpClient = new HttpClient();
var html = await httpClient.GetStringAsync("https://www.litoralulromanesc.ro/oferte_litoral.htm");
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(html);
// Select all hotel offer containers
var offerNodes = htmlDocument.DocumentNode.SelectNodes("//div[contains(@class, 'hotel_box')]");
if (offerNodes != null)
{
foreach (var offerNode in offerNodes)
{
// Extract hotel name
var hotelName = offerNode.SelectSingleNode(".//div[@class='hotel_name']")?.InnerText.Trim();
// Extract location
var location = offerNode.SelectSingleNode(".//div[@class='statiune']")?.InnerText.Trim();
// Extract price
var price = offerNode.SelectSingleNode(".//div[contains(@class, 'pret')]")?.InnerText.Trim();
// Extract period
var period = offerNode.SelectSingleNode(".//div[@class='perioada']")?.InnerText.Trim();
if (!string.IsNullOrEmpty(hotelName))
{
Console.WriteLine("\nHotel Found:");
Console.WriteLine($"Name: {hotelName}");
Console.WriteLine($"Location: {location}");
Console.WriteLine($"Price: {price}");
Console.WriteLine($"Period: {period}");
Console.WriteLine("------------------------");
}
}
}
else
{
Console.WriteLine("No offers found. The website structure might have changed.");
}