Hello. Made a parser that gets the contents of the block and converts it into text. Then I chose fields of interest from this text, one of which was “size”.

//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { public void button1_Click(object sender, EventArgs e) { 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("http://rutor.is/") }) { HtmlAgilityPack.HtmlDocument HD = new HtmlAgilityPack.HtmlDocument(); HD.LoadHtml(client.GetStringAsync("/torrent/496895/fizruk-03x01-05-iz-20-2016-satrip").Result); //можно делать все асинхронно. var element = HD.DocumentNode.SelectSingleNode("//table[@id='details']");//искомый элемент richTextBox1.Text = element.InnerText; } } richTextBox1.SaveFile("file.txt", RichTextBoxStreamType.PlainText); string text = File.ReadAllText("file.txt", Encoding.GetEncoding(1251)); Encoding ascii = Encoding.UTF8; Encoding unicode = Encoding.Unicode; string[] lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); richTextBox1.Clear(); for (int i = 0; i<lines.Length; i++) { this.richTextBox1.Text += lines[i] + "\n"; } richTextBox1.SaveFile("file.txt", RichTextBoxStreamType.PlainText); StreamReader sr = new StreamReader("file.txt", System.Text.Encoding.Default, false); string format_prim = "Формат:"; string reziser_prim = "Режиссер:"; string strana_prim = "Страна:"; string size_prim = "Разме"; string line = ""; string format = ""; string reziser = ""; string strana = ""; string size = ""; int formnatLenght = format_prim.Length; int reziserLenght = reziser_prim.Length; int stranaLenght = strana_prim.Length; int sizeLenght = size_prim.Length; while (!sr.EndOfStream) { line = sr.ReadLine(); if (line.Contains(format_prim)) { format = line.Substring(formnatLenght + 1); } if (line.Contains(reziser_prim)) { reziser = line.Substring(reziserLenght + 1); } if (line.Contains(strana_prim)) { strana = line.Substring(stranaLenght + 1); } if (line.Contains(size_prim)) { size = line.Substring(sizeLenght + 1); } } MessageBox.Show(format); MessageBox.Show(reziser); MessageBox.Show(strana); MessageBox.Show(size); } } } } 

So, the field "size" is obtained in the form "Size 1.40 GB (1500499968 Bytes)", which prevents me from processing it. Can someone tell me how to get these 1.40 GB without all the rest?

  • 2
    Well, the same fans came running to grab content from the router. If the site has an API, work through it. If the site does not have an API, it does not want to collect information from it, and you do not deserve any sympathy. - VladD

1 answer 1

  var full="Размер 1.40 GB (1500499968 Bytes)"; var size = fullsize.Split(new string[] { "Размер", "(" }, StringSplitOptions.RemoveEmptyEntries)[0]; 

Split divides the line into given separators. In this case, this is "Size" and "(". At the exit, we get an array of strings. We have this "1.40 GB" and 1500499968 Bytes). StringSplitOptions.RemoveEmptyEntries says to remove the empty strings obtained by splitting. [0] - selects the first element of the array - 1.40 GB.

  • Your option is not suitable, because He eventually gives me the word "Name." This time in the file the size field looks like this: Size 4.84 & nbsp; GB (5196844997 Bytes) - Andrey Fedorov
  • @Andrey Fedorov In your example, the original line is "Size 1.40 GB (1500499968 Bytes)", I do not see the word "Name" there. . A & nbsp is a space character. - Eugene Kidyaev
  • The parser, after processing the page of the site, receives the following text: shortText.com/77207ea2 (did not copy it here, because it does not fit all). The whole snag may be that in MediaInfo the word "size" is repeated several more times. And, quite possibly, your code selects it from there. I need to get the size from the "size" field, which is at the bottom. Can there be any other way to get the contents of that line? - Andrey Fedorov
  • @Andrey Fedorov, you asked a specific question, I answered it. If you want to ask something else, create a new question. Your link does not open. I do not know what data you have on the input and the structure of the Html that you parse. I can only advise you to look at CsQuery . Works on CSS selectors. If you know HTML and Css you can easily figure it out. - Eugene Kidyaev