Hello, I use for HAP to parse certain pages. It seems that everything is working fine, including the search for Kinopoisk, but here something does not work directly with the page of the film

using (HttpClientHandler handler = new HttpClientHandler() { AllowAutoRedirect = true, AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate }) { using (HttpClient client = new HttpClient(handler) { BaseAddress = new Uri("https://www.kinopoisk.ru/film/") }) { HtmlAgilityPack.HtmlDocument HD = new HtmlAgilityPack.HtmlDocument(); HD.LoadHtml(client.GetStringAsync("839219").Result); //ищем заголовок фильма var kinopoisk = HD.DocumentNode.SelectSingleNode("//title"); if (kinopoisk != null) { MessageBox.Show(kinopoisk.InnerText); } } } 

839219 is the id of the movie on the cinema search. Can someone tell me what I'm doing wrong? Parsing works with other sites of this kind, but not here ...

  • And client.GetStringAsync ("839219"). Result returns you html page then? Save it to a file, but open it in a browser. - Monk
  • I don’t really know what HAP is. But, judging by the name of the GetStringAsync method, it should be executed asynchronously. As a result, an empty string can be passed to the LoadHtml method. - Stepan Kasyanenko
  • Indeed, an empty string is passed ... Can you tell me how to fix this? Tried to check client.GetStringAsync ("839219"). IsCompleted, it did not help - Andrei Fedorov
  • GetStringAsync expects an address to enter, not some kind of Id. - Monk
  • Can you show how to transfer data based on my code? - Andrey Fedorov

1 answer 1

I myself have found a solution to the problem. It is possible to use both HtmlagillityPack and regulars.

 public void kinopoisk_time(string uri) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586"; request.Accept = "text/html, application/xhtml+xml, image/jxr, */*"; var responseToString = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.GetEncoding(1251)).ReadToEnd(); string time = Regex.Match(responseToString, @"id=""runtime"">(.*)мин", RegexOptions.IgnoreCase).Groups[1].Value; int tFilm = Convert.ToInt32(time); TimeSpan t = new TimeSpan(0, tFilm, 0); timeFilm.Text = t.ToString(); }