SOL9 Sample: HTMLParser

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * HTMLParser.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2012/02/17 Modified to use SOL::HTMLDocument and SOL::HTMLElement classes.

#include <sol\ole\HTMLParser.h>
#include <sol/html/HTMLDocument.h>
#include <sol/html/HTMLElement.h>

////////////////////////////////////////
// Program main

void _tmain(int argc, TCHAR** argv) {
  if (argc != 2) {
    printf("Usage:HTMLParser.exe htmlFileFullPath\n");
    return;
  }

  HRESULT hr = CoInitialize(NULL);
  if (FAILED(hr)) {
    return;
  }
  const TCHAR* filePath = argv[1];

  try {
    SOL::HTMLParser parser;

    hr = parser.loadFromFile(filePath);
    if (SUCCEEDED(hr)){
      _tprintf(_T("OK. Loaded an HTMLFile %s\n"), filePath);
      SOL::HTMLDocument doc = parser.getHTMLDocument();
      SOL::HTMLElement body = doc.getBody();

      _bstr_t bodyHtml = body.getOuterHTML();
      _tprintf(_T("BODY=[%s]\n"), (const TCHAR*)bodyHtml);
      _bstr_t innerText = body.getInnerText();
      _tprintf(_T("InnterText=[%s]\n"), (const TCHAR*)innerText);

    } else {
      _tprintf(_T("ERROR=[%x]. Failed to load an HTMLFile %s\n"), hr, filePath);
    }

  } catch (_com_error& ex) {
    _tprintf(_T("Com error %s\n"), (const TCHAR*)ex.ErrorMessage());
  } catch (HRESULT hr) {
    _tprintf(_T("Exception: %x\n"), hr);
  }
  CoUninitialize();
}



Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.