尝试使用 investing.com 中的数据创建新闻专家

Trying to create a news expert using data from investing.com

找到下面附上的代码,于是ReadCBOE函数从investing.com中读取信息并保存到string str中,Update news函数再分析从ReadCBOE中得到的信息并存入相关数组中,代码为运行 没有任何错误只是无法弄清楚为什么信息没有正确存储到数组中。 ps 相同的代码在 mt4 上完美运行

//---------------------------------------------------------------------+     
string ReadCBOE()
      {
       string cookie=NULL,headers;
       char post[],result[];     string TXT="";
       int res;
       string str;
    
       string google_url="http://ec.forexprostools.com/?columns=exc_currency,exc_importance&importance=1,2,3&calType=week&timeZone=15&lang=1";
       ResetLastError();
       int timeout=5000; 
       res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
       if(res==-1)
         {
          Print("WebRequest error, err.code  =",GetLastError());
          MessageBox("You must add the address 'http://ec.forexprostools.com/' in the list of allowed URL tab 'Advisors' "," Error ",MB_ICONINFORMATION);
         }
       else
         {
          int filehandle=FileOpen("news-log.html",FILE_WRITE|FILE_BIN|FILE_ANSI);
          if(filehandle!=INVALID_HANDLE)
            {
             FileWriteArray(filehandle,result,0,ArraySize(result));
             FileClose(filehandle);
             
             //------
             int file_handle=FileOpen("news-log.html",FILE_READ|FILE_BIN|FILE_ANSI);
             if(file_handle!=INVALID_HANDLE)
                {
                   str=FileReadString(file_handle,int(FileSize(file_handle)));
                   FileClose(file_handle);
                }
             else PrintFormat("Failed to open %s file, Error code = %d","news-log.html",GetLastError());
            }
         }
       return(str);
       }
    
        //-------------------------------------------------------+ 
           void UpdateNews()
              {
               string TEXT=ReadCBOE();      
               int sh = StringFind(TEXT,"pageStartAt>")+12;
               int sh2= StringFind(TEXT,"</tbody>");
               TEXT=StringSubstr(TEXT,sh,sh2-sh);
               sh=0;
               while(!IsStopped())
                 {
                  sh = StringFind(TEXT,"event_timestamp",sh)+17;
                  sh2= StringFind(TEXT,"onclick",sh)-2;
                  if(sh<17 || sh2<0)break;
                  NewsArr[0][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
            
                  sh = StringFind(TEXT,"flagCur",sh)+10;
                  sh2= sh+3;
                  if(sh<10 || sh2<3)break;
                  NewsArr[1][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
                  
                  sh = StringFind(TEXT,"title",sh)+7;
                  sh2= StringFind(TEXT,"Volatility",sh)-1;
                  if(sh<7 || sh2<0)break;
                  NewsArr[2][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
                  if(StringFind(NewsArr[2][NomNews],"High")>=0 && !HighNews)continue;Print("Found");
                  if(StringFind(NewsArr[2][NomNews],"Moderate")>=0 && !MidleNews)continue;
                  if(StringFind(NewsArr[2][NomNews],"Low")>=0 && !LowNews)continue;
            
                  sh=StringFind(TEXT,"left event",sh)+12;
                  int sh1=StringFind(TEXT,"Speaks",sh);
                  sh2=StringFind(TEXT,"<",sh);
                  if(sh<12 || sh2<0)break;
                  if(sh1<0 || sh1>sh2)NewsArr[3][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
                  else NewsArr[3][NomNews]=StringSubstr(TEXT,sh,sh1-sh);
            
                  NomNews++;
                  if(NomNews==300)break;
                 }
              }

尝试下面的代码,它应该适用于较大的字符串。

string ReadCBOE()
{
   string cookie=NULL,headers;
   char post[],result[];     string TXT="";
   int res;
   string str;

   string google_url="http://ec.forexprostools.com/?columns=exc_currency,exc_importance&importance=1,2,3&calType=week&timeZone=15&lang=1";
   ResetLastError();
   int timeout=5000; 
   res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
   if(res==-1)
   {
      Print("WebRequest error, err.code  =",GetLastError());
      MessageBox("You must add the address 'http://ec.forexprostools.com/' in the list of allowed URL tab 'Advisors' "," Error ",MB_ICONINFORMATION);
   }
   else
   {
      int filehandle=FileOpen("news-log.html",FILE_WRITE|FILE_BIN|FILE_ANSI);
      if(filehandle!=INVALID_HANDLE)
      {
         FileWriteArray(filehandle,result,0,ArraySize(result));
         FileClose(filehandle);
         //------
         int file_handle=FileOpen("news-log.html",FILE_READ|FILE_BIN|FILE_ANSI);
         if(file_handle!=INVALID_HANDLE)
         {
            do
            {
               ResetLastError();
               string Largestr=FileReadString(file_handle,4000);
               if(GetLastError()!=0) break;
               StringConcatenate(str,str,Largestr);
            }
            while(GetLastError()==0 && !FileIsEnding(file_handle));
            FileClose(file_handle);
         }
         else PrintFormat("Failed to open %s file, Error code = %d","news-log.html",GetLastError());
      }
   }
return(str);
}