SOL9 Sample: HTMLDocumentFromUrl
|
1 Screenshot
2 Source code
/*
* HTMLDocumentFromUrl.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2012/02/18
#include <sol/COMInitializer.h>
#include <sol/Locale.h>
#include <sol/html/HTMLDocument.h>
#include <sol/html/HTMLElement.h>
#include <sol/html/HTMLElementCollection.h>
int _tmain(int argc, _TCHAR* argv[])
{
if (argc != 2) {
_tprintf(_T("Usage:%s url\n"), argv[0]);
return 0;
}
COMInitializer initializer;
Locale locale;
try {
SOL::HTMLDocument document;
//Create an HTMLDocument
document.createDocument();
//Try to write NULL empty string to the document.
document.write(NULL);
//Close it.
document.close();
//Put the designMode of the document to be 'on'.
document.putDesignMode(_bstr_t("on"));
_bstr_t url = argv[1];
_bstr_t option = "null";
//Create a newDocument from the document with the url.
SOL::HTMLDocument newDocument = document.createDocumentFromUrl(url, option);
//But, we have to wait until the readyState of the newDocument becomes 'complete'.
newDocument.waitForComplete();
SOL::HTMLElement body = newDocument.getBody();
_bstr_t bodyHtml = body.getInnerHTML();
_tprintf(_T("%s\n"), (const TCHAR*)bodyHtml);
} catch (Exception& ex) {
ex.printf();
} catch (HRESULT hr) {
printf("Exception hr=%x\n", hr);
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.