using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
public static string SubstringJson(this string value, string start, string end)
var startIndex = value.IndexOf(start) + start.Length;
var endIndex = value.IndexOf(end) - startIndex;
var result = value.Substring(startIndex, endIndex).Trim();
return result.Remove(result.Length - 1);
public static int SubstringId(this string url)
var result = new Uri(url).AbsolutePath.Split('-').FirstOrDefault()?.Remove(0, 2);
return int.Parse(result);
static readonly HttpClient client = new HttpClient();
private static async Task<JObject> GetJsonAsync(string url)
var html = await client.GetStringAsync(url);
var jsonString = html.SubstringJson("window.ApolloCacheState =", "window.SPAConfig");
return JObject.Parse(jsonString);
private async static Task ParseItem(string itemUrl)
var id = itemUrl.SubstringId();
var json = await GetJsonAsync(itemUrl);
var product = json[$"Product:{id}"];
var Product = JsonConvert.DeserializeObject<Product>(product.ToString());
var companyId = product["company"]["id"];
var company = json[$"{companyId}"];
var Company = JsonConvert.DeserializeObject<Company>(company.ToString());
var builder = new StringBuilder();
builder.AppendLine($"{Product.Name}");
builder.AppendLine($"Картинки");
foreach(var image in Product.Images.Json)
builder.AppendLine($"{image}");
builder.AppendLine($"Цена {Product.Price} {Product.PriceCurrencyLocalized} ({Product.PriceUsd} usd.) ");
builder.AppendLine($"Компания:{Company.Name} г.{Company.City}");
builder.AppendLine($"Контакт: {Company.ContactPerson} {Company.Phone} {Company.WebSite}");
Console.WriteLine(builder);
await ParseItem("https://prom.ua/p1097470680-halat-zhenskij-dlinnyj.html");