Answer the question
In order to leave comments, you need to log in
Parser of members of VK groups. Having trouble loading your groups?
(semi-finished layout)
For development, I decided to write such a parser for community members in contact. Unable to upload list of my groups to listBox. Tell me what I'm doing wrong. How to make a request?
private string GET(string Url)
{
var reqGet = WebRequest.Create(Url);
var resp = reqGet.GetResponse();
var stream = resp.GetResponseStream();
var sr = new StreamReader(stream);
var Out = sr.ReadToEnd();
sr.Close();
return Out;
}
private string POST(string Url, string Data)
{
ServicePointManager.Expect100Continue = false;
var cookies = new CookieContainer();
var reqPost = (HttpWebRequest) WebRequest.Create(Url);
reqPost.CookieContainer = cookies;
reqPost.Method = "POST";
reqPost.Timeout = 100000;
reqPost.ContentType = "application/x-www-form-urlencoded";
byte[] sentData = Encoding.UTF8.GetBytes(Data);
reqPost.ContentLength = sentData.Length;
var sendStream = reqPost.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
using (var responseStream = reqPost.GetResponse().GetResponseStream())
using (var reader = new StreamReader(responseStream))
{
string Out = reader.ReadToEnd();
return Out;
}
}
private void http_auth_vk(string login, string pass)
{
//*****************************
//Получаем action_url
//*****************************
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
string Out = GET("http://m.vk.com/");
//*****************************
//Парсим
//*****************************
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(Out);
var bodyNode = doc.DocumentNode.SelectSingleNode("//div[@class='form_item fi_fat']/form");
var _result = bodyNode.Attributes["action"].Value;
//*****************************
//POST запрос
//*****************************
string data = "email=" + login + "&pass=" + pass;
Out = POST(_result, data);
//*****************************
//Парсим, поиск ID
//*****************************
doc.LoadHtml(Out);
try
{
bodyNode = doc.DocumentNode.SelectSingleNode("//h2[@class='op_header']/a");
labelUserInfo.Text = bodyNode.InnerText + " - ";
bodyNode = doc.DocumentNode.SelectSingleNode("//div[@class='ip_user_link']/a");
labelUserInfo.Text += "ID " + bodyNode.Attributes["href"].Value.Substring(3);
bodyNode = doc.DocumentNode.SelectSingleNode("//div[@class='ip_user_link']/a/img");
userImg.Load(bodyNode.Attributes["src"].Value);
bodyNode = doc.DocumentNode.SelectSingleNode("//ul[@class='left_footer_menu']/li[4]/a");
_logOut = bodyNode.Attributes["href"].Value;
//Если ID найден, то авторизация удалась
LoadGroup();
}
catch
{
//Если ID не найден, то авторизация не удалась
MessageBox.Show("Авторизация не удалась. Возможно там капча=(");
this.buttonCnct.Enabled = true;
this._login.Enabled = true;
this._pass.Enabled = true;
}
}
private void LoadGroup()
{
string Out = ;
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(Out);
HtmlNodeCollection nodes =
doc.DocumentNode.SelectNodes("//div[@id='gr_search_items']/a[@class='simple_fit_item']");
foreach (var node in nodes)
{
}
}
Answer the question
In order to leave comments, you need to log in
Why are you parsing m.vk.com if everything you need can be obtained through the API?
https://vk.com/dev/groups.get
UPD.:
You obviously didn't show all the code.
To get a list of groups, you need to make a POST to the address m.vk.com/groups?tab=groups
In your code, I see only authorization and LoadGroup () which should parse HTML which is not. Why not? Yes, because it is generated by Ajax in response to POST m.vk.com/groups?tab=groups
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question