[python-win32] IE DOM ptr as input to DLL function - Doingthisright?
Richard Bell
rbell01824 at earthlink.net
Sun Jul 1 17:45:45 CEST 2007
Jef,
I'm not sure if this is helpful but you might try taking a look at the Pamie
code for how it gets deals with the DOM.
Additionally the following code snip may be helpful (self is
win32com.Client.Dispatch returned IE object)
Regards,
Richard
----- code -----
def Dom(self,
errorFlag = True, message = None ):
""" Sets Yamie's dom attribute (topmost element of the page's DOM
tree).
yie.Dom([errorFlag,][errorMessage])->object #HTML element in the DOM
tree
The DOM is rebuilt after each navigation. Previous values are no
longer good.
Parameters:
errorFlag (boolean) If True, COM error messages are written to
stderr.
Otherwise, COM error messages are surpressed.
message (string) A message to output on COM errors.
Returns:
dom (object) The topmost element in the page's DOM tree.
dom is None on COM error.
Set status and comError.
Usage:
>>> dom = yie.Dom()
>>> print dom #doctest: +ELLIPSIS
<win32com.gen_py.Microsoft HTML Object Library.DispHTMLHtmlElement
instance at 0x...>
>>> print dom.CLSID
{3050F560-98B5-11CF-BB82-00AA00BDCE0B}
>>> len(dir(dom))
65
>>> len(dom._prop_map_get_.keys())
130
>>> dir(dom) == ['CLSID', 'FireEvent', '_ApplyTypes_', '__cmp__',
'__doc__',
... '__getattr__', '__init__', '__module__', '__repr__',
'__setattr__', '_get_good_object_',
... '_get_good_single_object_', '_oleobj_', '_prop_map_get_',
'_prop_map_put_',
... 'addBehavior', 'addFilter', 'appendChild', 'applyElement',
'attachEvent', 'blur',
... 'clearAttributes', 'click', 'cloneNode', 'coclass_clsid',
'componentFromPoint',
... 'contains', 'createControlRange', 'detachEvent', 'doScroll',
'dragDrop', 'focus',
... 'getAdjacentText', 'getAttribute', 'getAttributeNode',
'getBoundingClientRect',
... 'getClientRects', 'getElementsByTagName', 'getExpression',
'hasChildNodes',
... 'insertAdjacentElement', 'insertAdjacentHTML',
'insertAdjacentText', 'insertBefore',
... 'mergeAttributes', 'normalize', 'releaseCapture',
'removeAttribute',
... 'removeAttributeNode', 'removeBehavior', 'removeChild',
'removeExpression',
... 'removeFilter', 'removeNode', 'replaceAdjacentText',
'replaceChild', 'replaceNode',
... 'scrollIntoView', 'setActive', 'setAttribute',
'setAttributeNode', 'setCapture',
... 'setExpression', 'swapNode', 'toString']
True
>>> dom._prop_map_get_.keys()== ['all', 'contentEditable',
'parentElement',
... 'onrowsinserted', 'disabled', 'filters', 'onrowexit',
'children', 'style',
... 'ondataavailable', 'nodeName', 'ondatasetchanged', 'clientLeft',
'accessKey',
... 'offsetLeft', 'ondatasetcomplete', 'currentStyle', 'hideFocus',
'onclick', 'onkeypress',
... 'onbeforeupdate', 'onpropertychange', 'onresizestart',
'onmouseover', 'recordNumber',
... 'onscroll', 'onrowenter', 'clientHeight', 'onmouseenter',
'canHaveChildren', 'onkeyup',
... 'readyStateValue', 'onreadystatechange', 'dir', 'tagUrn',
'onfocusout', 'innerHTML',
... 'className', 'ondeactivate', 'onmoveend', 'ondragleave',
'glyphMode', 'onresize',
... 'version', 'onresizeend', 'offsetTop', 'onfocus', 'ondrag',
'previousSibling',
... 'onfocusin', 'nodeType', 'onbeforeeditfocus', 'onkeydown',
'outerText', 'onbeforecopy',
... 'language', 'title', 'firstChild', 'oncut',
'onbeforedeactivate', 'attributes',
... 'onmove', 'offsetParent', 'behaviorUrns', 'clientWidth',
'outerHTML', 'tagName',
... 'offsetHeight', 'onerrorupdate', 'onbeforepaste', 'childNodes',
'tabIndex',
... 'scrollWidth', 'onpage', 'isDisabled', 'onhelp',
'oncontrolselect', 'onmouseup',
... 'onmousemove', 'isMultiLine', 'onblur', 'onmouseout',
'oncellchange', 'sourceIndex',
... 'scrollLeft', 'parentTextEdit', 'onmousewheel', 'lastChild',
'scrollHeight',
... 'oncontextmenu', 'onrowsdelete', 'readyState', 'inflateBlock',
'onlayoutcomplete',
... 'innerText', 'onmovestart', 'offsetWidth', 'uniqueID',
'onafterupdate', 'ondragenter',
... 'nextSibling', 'onmousedown', 'clientTop', 'parentNode',
'oncopy', 'onfilterchange',
... 'id', 'ondrop', 'isTextEdit', 'onbeforecut', 'ownerDocument',
'onactivate',
... 'runtimeStyle', 'document', 'isContentEditable', 'ondragstart',
'onmouseleave',
... 'uniqueNumber', 'scrollTop', 'onpaste', 'ondragover', 'lang',
'ondragend',
... 'canHaveHTML', 'scopeName', 'nodeValue', 'onlosecapture',
'onbeforeactivate',
... 'ondblclick', 'onselectstart']
True
"""
try:
node = self.Document.all.tags("HTML")
self.dom = node.item(0)
return self.dom
except pythoncom.com_error, (hr, hrtxt, addinfo, arg):
self.dom = None
if not message: message = 'Dom error'
self._ComError( errorFlag, message, hr, hrtxt, addinfo, arg)
return None
|-----Original Message-----
|From: python-win32-bounces at python.org [mailto:python-win32-
|bounces at python.org] On Behalf Of Mark Hammond
|Sent: Friday, June 29, 2007 11:47 PM
|To: 'Jef Allbright'; python-win32 at python.org
|Subject: Re: [python-win32] IE DOM ptr as input to DLL function -
|Doingthisright?
|
|> I'm a newbie to Win32 COM and am unsure whether my current problem
|> lies in what I'm doing or possibly in some quirk of the DLL I'm trying
|> to use from Python.
|>
|> I have a snippet of C++ that I want to implement in Python:
|>
|> IDispatch* pVoid;
|> m_pBrowserApp->get_Document(&pVoid);
|> m_pAnalyzer->Analyze(pVoid, _variant_t(5L));
|> pVoid->Release();
|>
|> At first, I tried using win32com.Client.Dispatch to create a COM
|> object for both my DLL and for the IE browser, and that worked well up
|> to the point where I tried to use the ie.Document object as input to
|> Analyze where it expects the pVoid. Got "argument is not a COM
|> object"
|
|In general, COM itself doesn't understand a "void *". In the example
|above,
|that first param would probably be best defined as IUnknown rather than
|void. Further, in general, win32com only supports IDispatch based
|interfaces, but the C++ example above is using vtables. If you can get
|your
|analyzer interface working via IDispatch, it will work correctly from
|Python, as well as VBScript, JS, etc...
|
|I'm afraid I can't help with the comtypes issues...
|
|Cheers,
|
|Mark
|
|_______________________________________________
|Python-win32 mailing list
|Python-win32 at python.org
|http://mail.python.org/mailman/listinfo/python-win32
More information about the Python-win32
mailing list