Advertisement
Riremito

html parser test

Apr 10th, 2017
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1.  
  2. Log log("rakuen.txt");
  3.  
  4. void machine(Brynhildr *br, char *url);
  5. void machinelist(Brynhildr *br, char *url){
  6.     br->Open(url);
  7.     HTMLParser hp(br->Read());
  8.     HTMLTag *ht;
  9.     char href[256];
  10.     int i = 0;
  11.     br->Close();
  12.     while(1){
  13.         ht = hp.Find("div id=\"model_link\"->ul->a", i++);//機種
  14.         if(!ht){
  15.             break;
  16.         }
  17.         //if(!strstr(ht->GetText(), "ジャグラー")){
  18.             ht->Get("href", href);
  19.             printf("%s\n", ht->GetText());
  20.             log.Write(ht->GetText());
  21.             machine(br, href);
  22.         //}
  23.     }
  24.     ht = hp.Find("div class=\"list_navigation\"->div style=\"float:right;\"->a");//次へ
  25.     if(ht){
  26.         ht->Get("href", href);
  27.         return machinelist(br, href);
  28.     }
  29. }
  30.  
  31. void lastgame(Brynhildr *br, char *url){
  32.     br->Open(url);
  33.     HTMLParser hp(br->Read());
  34.     HTMLTag *ht;
  35.     int i = 0;
  36.     br->Close();
  37.     ht = hp.Find("head->title");
  38.     if(ht){
  39.         if(strcmp(ht->GetText(), "エラーページ") == 0){
  40.             Sleep(3000);
  41.             return lastgame(br, url);
  42.         }
  43.     }
  44.     ht = hp.Find("td align=\"right\"", 2);
  45.     if(ht){
  46.         if(!hp.Find("td align=\"right\"", 5)){
  47.             printf("@");
  48.             log.Write("@", false);
  49.         }
  50.         printf("%sg\n", ht->GetText());
  51.         log.Write(ht->GetText(), false);
  52.         log.Write("g");
  53.     }
  54.     else{
  55.         Sleep(500);
  56.         return lastgame(br, url);
  57.     }
  58. }
  59.  
  60. void rireki(Brynhildr *br, char *top){
  61.     br->Open(top);
  62.     HTMLParser hp(br->Read());
  63.     HTMLTag *ht;
  64.     int i = 0;
  65.     char href[256];
  66.     br->Close();
  67.     while(1){
  68.         ht = hp.Find("div class=\"daiban\"", i++);
  69.         if(ht){
  70.             ht = ht->GetParent();//link
  71.             ht->Get("href", href);
  72.             printf("%s:", ht->GetText());
  73.             log.Write(ht->GetText(), false);
  74.             log.Write(":", false);
  75.             Sleep(2000);
  76.             lastgame(br, href);
  77.         }
  78.         else{
  79.             break;
  80.         }
  81.     }
  82. }
  83.  
  84. void machine(Brynhildr *br, char *url){
  85.     br->Open(url);
  86.     HTMLParser hp(br->Read());
  87.     HTMLTag *ht;
  88.     char href[256];
  89.     int i = 0;
  90.     br->Close();
  91.     while(1){
  92.         ht = hp.Find("div id=\"menu_link\"->ul->a", i++);//大当たり履歴データ
  93.         if(!ht){
  94.             break;
  95.         }
  96.         if(ht->GetText() && strstr(ht->GetText(), "大当り履歴データ")){
  97.             ht->Get("href", href);
  98.             rireki(br, href);
  99.             break;
  100.         }
  101.     }
  102. }
  103.  
  104. int main(){
  105.     Brynhildr br("http://www.d-deltanet.com/");
  106.     br.Open("http://www.d-deltanet.com/pc/D0101.do?pmc=22021006");
  107.     HTMLParser hp(br.Read());
  108.     HTMLTag *ht;
  109.     char href[256];
  110.     char *tt;
  111.     int i = 0;
  112.  
  113.     while(1){
  114.         ht = hp.Find("a", i++);
  115.         if(ht && ht->Get("href", href) && ht->GetText()){
  116.             if(strstr(ht->GetText(), "【20】スロ")){
  117.                 break;
  118.             }
  119.         }
  120.         else{
  121.             break;
  122.         }
  123.     }
  124.     br.Close();
  125.     machinelist(&br, href);
  126.     //machine(&br);
  127.     return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement