추출값 : 금시세

//---------------------------------------------------------------------------
// 인터페이스를 사용하기 위한 헤더파일
#include <mshtml.h>
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    Caption = "시세추출중";

    // 웹 페이지 로드
    CppWebBrowser1->Navigate( L"사이트주소은폐ㅋㅋ" );
}
//---------------------------------------------------------------------------
AnsiString __fastcall ExtractMoney( AnsiString Value )
{
    // 문자열 파싱

    // 시세 문자열에서 금액 숫자값만 추출, [xx시세00,000원등락수치]
    int begin = Value.Pos( "세" ) + 2;

    // 시세 숫자에서 Comma, Space 제거
    return StringReplace(
        // '세' 와 '원' 사이의 Money 문자열 추출
        Value.SubString( begin, Value.Pos( "원" ) - begin ),
        ",",
        "",
        TReplaceFlags() << rfReplaceAll
    ).Trim();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender,
      LPDISPATCH pDisp, Variant *URL)
{
    WideString Value;

    // CppWebBrowser 의 Document 참조
    IDispatch *Document = CppWebBrowser1->Document;
    IHTMLElement *HTMLElement;
    IHTMLDocument2 *pHTMLDocument;

    // CppWebBrowser->Document 소스 가져오기, Text 형식

    // Document 에서 IHTMLDocument2 인터페이스 가져오기
    if ( Document->QueryInterface( IID_IHTMLDocument2, ( PVOID* )( &pHTMLDocument ) ) == S_OK )
    {
        // IHTMLDocument2 에서 Body 부를 IHTMLElement 인터페이스로 가져오기
        if ( pHTMLDocument->get_body( &HTMLElement ) == S_OK )
        {
            // IHTMLElement (Body) 의 Text 값 추출
            HTMLElement->get_innerText( &Value );

            // IHTMLElement 인터페이스 해제
            HTMLElement->Release();
        }
        // IHTMLDocument2 인터페이스 해제
        pHTMLDocument->Release();
    }

    // TMemo 를 이용하여 시세부분 TStrings 변환, 라인별로 24K,18K,14K 순
    Memo1->Lines->Clear();

    // '순금시세' 부터 '순금매입가' 까지가 금시세다.
    int begin = Value.Pos( "순금시세" );
    Memo1->Lines->Add( Value.SubString( begin, Value.Pos( "순금매입가" ) - begin ) );

    // 각 시세 값을 TEdit 에 대입
    Edit1->Text = ExtractMoney( Memo1->Lines->Strings[0] );
    Edit2->Text = ExtractMoney( Memo1->Lines->Strings[1] );
    Edit3->Text = ExtractMoney( Memo1->Lines->Strings[2] );

    Caption = "시세추출완료";
}
//---------------------------------------------------------------------------

'Windows > RAD Studio' 카테고리의 다른 글

[CB] KeyPad Virtual Key Value  (0) 2007.06.09
[DEL] Deprecated Lists  (0) 2007.06.02
[CB] 문자열 변환/검증  (0) 2007.05.30
[CB] TQuickRep 출력순서  (1) 2007.05.13
[CB] 쓰레드끼리는 마구 침범할 수 없다.  (0) 2007.04.15

+ Recent posts