dailyfx抓取新闻写法

void News_dailyfx()
  {
   if(IsTesting())return;
   string cookie=NULL,headers,str3=" ";
   char post[],result[],figli[];
   int res;
   new_i=0;
   ArrayFree(news_time);
   string google_url="https://www.dailyfx.com/calendar";
   ResetLastError();
   int timeout=5000; //--- timeout менее 1000 (1 сек.) недостаточен при низкой скорости Интернета 
   res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
   if(res==-1)
     {
      Print("Error in WebRequest. Error code =",GetLastError());
      //--- возможно, URL отсутствует в списке, выводим сообщение о необходимости его добавления 
      MessageBox("You must add an address '"+google_url+"' to the list of allowed URL on the tab 'Expersts'","Error",MB_ICONINFORMATION);
     }

   string str1=StringSubstr(Symbol(),0,3);
   string str2=StringSubstr(Symbol(),3,3);

   datetime news1;
   j=0;
   while(j<ArraySize(result)-10)
     {
      if(CharToStr(result[j])+CharToStr(result[j+1])+CharToStr(result[j+2])+CharToStr(result[j+3])+CharToStr(result[j+4])+CharToStr(result[j+5])+CharToStr(result[j+6])+CharToStr(result[j+7])=="id=\"date")
        {
         jj=j;
         while(jj<ArraySize(result)-10)
           {
            if(
               (CharToStr(result[jj])+CharToStr(result[jj+1])+CharToStr(result[jj+2])+CharToStr(result[jj+3])+CharToStr(result[jj+4])==">Low<") || 
               (CharToStr(result[jj])+CharToStr(result[jj+1])+CharToStr(result[jj+2])+CharToStr(result[jj+3])+CharToStr(result[jj+4])+CharToStr(result[jj+5])+CharToStr(result[jj+6])+CharToStr(result[jj+7])==">Medium<") || 
               (CharToStr(result[jj])+CharToStr(result[jj+1])+CharToStr(result[jj+2])+CharToStr(result[jj+3])+CharToStr(result[jj+4])+CharToStr(result[jj+5])==">High<")
               )
              {
               Draw=false;
               if(
                  (CharToStr(result[jj])+CharToStr(result[jj+1])+CharToStr(result[jj+2])+CharToStr(result[jj+3])+CharToStr(result[jj+4])==">Low<" && NewsWeak) || 
                  (CharToStr(result[jj])+CharToStr(result[jj+1])+CharToStr(result[jj+2])+CharToStr(result[jj+3])+CharToStr(result[jj+4])+CharToStr(result[jj+5])+CharToStr(result[jj+6])+CharToStr(result[jj+7])==">Medium<" && NewsMedium) || 
                  (CharToStr(result[jj])+CharToStr(result[jj+1])+CharToStr(result[jj+2])+CharToStr(result[jj+3])+CharToStr(result[jj+4])+CharToStr(result[jj+5])==">High<" && NewsStrong)
                  )
                 {
                  Draw=true;
                 }

               if(Draw)
                 {
                  jjj=j;
                  news1=0;
                  while(jjj<jj)
                    {
                     if(CharToStr(result[jjj])==">")
                       {
                        str3=CharToStr(result[jjj+1])+CharToStr(result[jjj+2])+CharToStr(result[jjj+3])+CharToStr(result[jjj+4])+CharToStr(result[jjj+5])+CharToStr(result[jjj+6])+CharToStr(result[jjj+7])+CharToStr(result[jjj+8])+
                             CharToStr(result[jjj+9])+CharToStr(result[jjj+10])+CharToStr(result[jjj+11])+CharToStr(result[jjj+12])+CharToStr(result[jjj+13])+CharToStr(result[jjj+14])+CharToStr(result[jjj+15])+
                             CharToStr(result[jjj+16])+CharToStr(result[jjj+17])+CharToStr(result[jjj+18])+CharToStr(result[jjj+19]);
                        StringReplace(str3,"-",".");
                        StringReplace(str3,"T"," ");
                        news1=StrToTime(str3);
                        news1=news1+TimeSetting*3600;
                        str3=TimeToString(news1,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
                        jjj=jj;
                       }
                     jjj++;
                    }

                  jjj=j;
                  while(jjj<jj)
                    {
                     if(CharToStr(result[jjj])+CharToStr(result[jjj+1])+CharToStr(result[jjj+2])+CharToStr(result[jjj+3])+CharToStr(result[jjj+4])+CharToStr(result[jjj+5])+CharToStr(result[jjj+6])+
                        CharToStr(result[jjj+7])+CharToStr(result[jjj+8])+CharToStr(result[jjj+9])=="<br></div>")
                       {
                        if(
                           CharToStr(result[jjj+10])+CharToStr(result[jjj+11])+CharToStr(result[jjj+12])==str1 ||
                           CharToStr(result[jjj+10])+CharToStr(result[jjj+11])+CharToStr(result[jjj+12])==str2
                           )
                          {
                           ArrayResize(news_time,new_i+1);
                           news_time[new_i]=news1;
                           new_i++;
                           ObjectDelete(_Name+"_"+IntegerToString(new_i)+"_"+str3);
                           if(ObjectCreate(0,_Name+"_"+IntegerToString(new_i)+"_"+str3,OBJ_TREND,0,news1,0,news1,Bid))
                             {
                              ObjectSetInteger(0,_Name+"_"+IntegerToString(new_i)+"_"+str3,OBJPROP_COLOR,ColorNews);
                              ObjectSetInteger(0,_Name+"_"+IntegerToString(new_i)+"_"+str3,OBJPROP_STYLE,LineStyle);
                              ObjectSetInteger(0,_Name+"_"+IntegerToString(new_i)+"_"+str3,OBJPROP_RAY_RIGHT,true);
                              ObjectSetInteger(0,_Name+"_"+IntegerToString(new_i)+"_"+str3,OBJPROP_SELECTABLE,false);
                             }
                           else
                              Print(GetLastError());
                          }
                        jjj=jj;
                       }
                     jjj++;
                    }
                 }
               jj=ArraySize(result);

              }
            jj++;
           }
        }
      j++;
     }
  }
本博客所有文章如无特别注明均为原创。作者:天泓评测
分享到:更多

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)