onilink_

Parsing twitter followers

May 31st, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <onidev/markup.h>
  2. #include <onidev/core/tools.h>
  3. #include <algorithm>
  4.  
  5. int main()
  6. {
  7.     std::vector<std::string> users;
  8.    
  9.     using namespace od;
  10.     auto node = HtmlNode::parseString( fileReadText("centauri_followers.html") );
  11.     HtmlNode* root = node->findRec("div", "class", "GridTimeline-items");
  12.    
  13.     for(auto& n: root->childs())
  14.     {
  15.         for(auto& n2: n->childs())
  16.         {
  17.             HtmlNode* n3 = n2->findRec("a");
  18.             users.push_back(n3->findAttribute("href"));
  19.         }
  20.     }
  21.     FILE* f = fopen("centauri_followers.txt", "w");
  22.     for(auto& user: users)
  23.         fprintf(f, "%s\n", user.c_str());
  24.     fclose(f);
  25.  
  26.     return 0;
  27. }
Add Comment
Please, Sign In to add comment