I am writing a parser, and for now just for the test you need to display the number of pages with users. There are 2 functions (the code will be lower). One - parsit the number of the last page with users, the second - displays the messagebox message in the window application. When compiling, the program first falls into catch, and issues " The index is outside the array ", then the application returns 0 (just the initial value of the variable, which for some reason has not changed). There is no problem with the connected xNet library. Just in case, I just connected all possible xNet:

using xNet; using xNet.Collections; using xNet.IO; using xNet.Security; using xNet.Threading; using xNet.Xml; using xNet.Net; using xNet.Text; 

The result is the same. Substring, as it seems to me, I seem to be correctly isolating the data (I also attach the source code of the page from the browser)

 <a href="/forum/users/?PAGEN_1=2" class="">2</a> <a href="/forum/users/?PAGEN_1=3" class="">3</a> <a href="/forum/users/?PAGEN_1=4" class="">4</a> <a href="/forum/users/?PAGEN_1=5" class="">5</a> <span class="forum-page-dots">...</span> <a href="/forum/users/?PAGEN_1=1654">1654</a> //Нужная строка 

The first function that parses:

 private int GetPages() { int countPages = 0; try { using(var Request = new HttpRequest()) { string sourcePage; sourcePage = Request.Get("http://vegeterian.ru/forum/users/").ToString(); countPages = Convert.ToInt32(sourcePage.Substring("/forum/users/?PAGEN_1=", "\">", 0)[4]); MessageBox.Show(sourcePage); } } catch(Exception ex) { MessageBox.Show(ex.Message); } return countPages; } 

The second function:

 private void UI_Load(object sender, EventArgs e) { string pcount = GetPages().ToString(); MessageBox.Show(pcount); } 

In addition to what was written above, I decided to check if I get html and what comes to me at all in sourcePage when I do:

 sourcePage = Request.Get("http://vegeterian.ru/forum/users/").ToString(); 

I compile and return to the window application: xNet.Net.HttpResponse

  • Read the Request on the Microsoft - msdn site to get started. There is even a minimal example. - nick_n_a
  • Thanks for the information. But while the question is open - can you tell where the error is in the code? - Deuse
  • ToString converts a class to a string with the name of the class, in rare cases returns the necessary information. You need perhaps Request.InputStream to read the body, or another method to use, but not ToString. There are many examples on the Internet how to read http, for example, msdn.microsoft.com/en-us/library/456dfw4f%28v=vs.110%29.aspx or stackoverflow.com/questions/3273205/read-text-from-response - nick_n_a
  • Thanks for the help. Just a little strange, since I did the same parsing as in the following example: youtube.com/watch?v=B7r9K_WM4SY Accordingly, I used methods identical to those on the video. And in the end I get the wrong result. - Deuse

0