Thursday, 19 June 2014

Read data from live website in Ax2012

With the help of following code we can easily read data from live website

static void ReaddataFromLivewebSite(Args _args)
{
    #DEFINE.BLOGCONTENT('http://www.lme.com/en-gb/metals/non-ferrous/copper/')
    int         curPos=1;
    int         endPos;
    int         startPos=1;
    str         data;
    str         internetURL;
    int         price;
    TextBuffer  textBuffer;
    System.Net.WebRequest request;
    System.Net.WebResponse response;
    System.IO.StreamReader  streamReader;

    request=System.Net.WebRequest::Create(#BLOGCONTENT);
    response= request.GetResponse();
    streamReader=new System.IO.StreamReader(response.GetResponseStream());
    textBuffer =new TextBuffer();
    textBuffer.setText('');
    data = streamReader.ReadToEnd();
    streamReader.Close();
    textBuffer.setText(data);
    textBuffer.regularExpressions(false);
    textBuffer.find('Cash Seller & Settlement', curPos);
    startPos=textBuffer.matchPos();
    textBuffer.find('3-months Buyer');
    endPos=textBuffer.matchPos();
    data=textBuffer.subStr(startPos, endPos - startPos);
    data =   strReplace(data,'',"");
    data =   strReplace(data,'',"");   
    data =   strReplace(data,' ',"");
    data =   strReplace(data,'',""); 
    internetURL= strRem(strreplace(data,'Cash Seller & Settlement',''),'"');
    price = str2int(internetURL);
    internetURL = int2str(price);
    info(internetURL);
    response.Close();

}

1 comment:

  1. Hello Muhammad,

    In my machine, this code does not work properly . could you send your email id for further communication.

    ReplyDelete