вторник, 25 октября 2011 г.

Парсинг , Граббинг Группы вконтакте

Собрать всех участников ( их ID ) какой-либо группы с сайта vkontakte.ru

для примера возьмем группу "Я ненавижу автомобили"

http://vk.com/search?c[section]=people&c[group]=1409939

function GetAllMembersPage($oid = 1409939, $offset = 0)
 {
  $this-> code = $this-> GetMembersPage($oid, $offset);

  if(preg_match_all ('~

В группе (.*) участников.

~', $this-> code, $m)) { $members_count = strip_tags($m[1][0]); $members_count = (int)str_replace (' ', '', $members_count); echo "нашли В группе $members_count участников"; //print_r($m); } $users_data[] = $this-> GetMembers(); $offset = 20; while ($offset < $members_count) { echo "i=$i "; echo "offset=$offset "; $this-> GetMembersPage($oid, $offset); $users_data[] = $this-> GetMembers(); $offset = $offset +20; } //print_r($users_data); foreach($users_data as $d) { foreach($d[1] as $k=>$v) { $users_data_w1[ $d[1][$k] ] = $d[2][$k]; $users_data_w_id[ $d[1][$k] ] = $d[1][$k]; } } $users_data_w_id = array_unique ($users_data_w_id); $this-> write_string("members_id.txt", '', "w"); foreach($users_data_w_id as $id) { $this-> write_string("members_id.txt", trim($id)."\n", "a"); } } //******************************** //* //* http://vk.com/al_page.php?act=show_members_box&al=1&gid=1409939&tab=members //* http://vk.com/al_page.php?act=show_members_box&al=1&gid=1409939&tab=members&offset=190 //* //******************************* function GetMembersPage($gid = 1409939, $offset=0) { $p = array ( "act" => "show_members_box", "al" => "1", "tab" => "members", "gid" => $gid, "offset" => $offset, ); $post_fields = http_build_query($p); $curl_data['post'] = $post_fields; $curl_data['followlocation'] = true; $curl_data['echo_header'] = true; $curl_data['referer'] = $this->site.""; $curl_data['url'] = $this->site."/al_page.php"; $this->code = $this->curl($curl_data); //print_r($this->code); $this-> write_string("show_members_box_log.htm", $this->code); return $this->code; } function GetMembers() { if(preg_match_all ('~(.*)~U', $this-> code, $m)) { //print_r($m); return $m; } else { return false; } }

На выходе имеем файл "members_id.txt"
вида

/skarrr
/id305045
/deviatio
/id538322
/arrtemy
/lerarunge
/id846721
/id1099400
/stigma
/stanislavre
/id1295336
/id1359451
/id1362725
/id1466790
/cor_serpentis
/id3801455
/id3917827
/id3960713
/jjozhkashut
/id4620731
/id4675099
/id4772386
/id5549687
/id7528496
/nastroy_voice
/slavin.anton
/id8381743
/id8888177
/id8919195
/id9414070
/id12545362
/id12614309
/id13689235
/eugeniy_victorovich
/id15446689
/id15749772
/id17258303
/id19105109
/amerius
/id21486556
/id22178446
/id24001470
/id24663151
/id25468242
/dokkdokk
/x_nemo_x
/id30769974
/pripyat_v_serdce
/id38287278
/id49674719
/yeticlub
/id54853271
/opium83w
/id68409528
/id68413777
/qwertypoint
/id94558605
/id128952800
/id132524251
/id135713564


скачать исходник:
http://rghost.ru/27066891

пасс: parsing-posting.blogspot.com

1 комментарий:

  1. Не могли бы перезалить исходник? Был бы весьма благодарен!

    ОтветитьУдалить