SOL9 Sample: HTMLElementCollection
|
1 Screenshot
2 Source code
/*
* HTMLElementCollection.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/com/EnumVariant.h>
#include <sol/html/HTMLDocument.h>
#include <sol/html/HTMLElement.h>
#include <sol/html/HTMLElementCollection.h>
#include <sol/html/HTMLLinkElement.h>
#include <sol/html/HTMLDOMNode.h>
int _tmain(int argc, _TCHAR* argv[])
{
if (argc != 2) {
_tprintf(_T("Usage:%s url or localFile\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();
//Try to display script tags.
SOL::HTMLElementCollection scripts = newDocument.getScripts();
scripts.display();
//Try to display all links.
SOL::HTMLElementCollection links = newDocument.getLinks();
//SOL::HTMLElementCollection links = newDocument.getElementsByTagName(_bstr_t("a"));
links.display();
//Try to display all nodes of 'img' tags.
SOL::HTMLElementCollection images = newDocument.getImages();
//SOL::HTMLElementCollection images = newDocument.getElementsByTagName(_bstr_t("img"));
images.display();
//Try to display all nodes of 'table' tags.
SOL::HTMLElementCollection tables = newDocument.getElementsByTagName(_bstr_t("table"));
tables.display();
} 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.