Syver Ensted and I have been exchanging email on this issue this morning, and
we've made a couple of discoveries:

- I found that I could load a URL and get to the document object by going
through the web browser object (from SHDocVw.dll).  My code looks like this:

browser = win32com.client.Dispatch('InternetExplorer.Application.1')
browser.Navigate(argv[1])
while browser.Busy:
    pass
print browser.LocationURL
doc = browser.Document
for elt in doc.all:
    print elt

- Syver suggested using urllib to load the URL, like so:

doc = win32com.client.Dispatch('htmlfile')
doc.write(urllib.urlopen(argv[1]).read())
for elt in doc.all:
   print elt

While both approaches work, Syver's is faster, I'm sure because the overhead is
less.  I would still like to understand why createDocumentFromUrl isn't working
as I expect, but I'm guessing that there is one or more other steps that have
to happen first (e.g., handling events).  But it's kind of tough to figure out
given the poor documentation of the mshtml library.

-- Dave

On Thu, 18 Jan 2001 08:34:25 -0800, Noah said:

> Hi,
>  
>  I copied your example exactly and I had the same problem; however,
>  I am using BeOpen Python 2.0 with the win32all extensions from ActiveState
>  installed as a separate package (win32all.exe, build 135). When I tried
>  to run createDocumentFromUrl I get a dialog window: 'python.exe - Application Error,
>  ...The memory could not be "read" ' The Visual C++ debugger shows an 
>  "Unhandled exception in python.exe (MSHTML.DLL): 0xC0000005: Access Violation". 
>  Note that the the context is "MSHTML! 700cd41a()". I have IE 5.50.4134.0600.
>  I'm not sure if all that helps. Maybe something is screwy with MSHTML.DLL.
>  
>  The following is what I typed (Note: the output does look slightly different):
>  
>       C:\Python20\win32com\client>python
>       Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
>       Type "copyright", "credits" or "license" for more information.
>       >>> import win32com.client
>       >>> o = win32com.client.Dispatch('htmlfile')
>       >>> o
>       <COMObject htmlfile>
>       >>> o.createDocumentFromUrl
>       <method CDispatch.createDocumentFromUrl of CDispatch instance at 007DE2BC>
>       >>> doc = o.createDocumentFromUrl ('192.168.1.1', None)
>       
>  I hope this gives you some more clues.
>  Yours,
>  Noah
>  
>  -----Original Message-----
>  From: [EMAIL PROTECTED]
>  [mailto:[EMAIL PROTECTED]]On Behalf Of Dave
>  Seidel
>  Sent: Thursday, January 18, 2001 3:42 AM
>  To: [EMAIL PROTECTED]
>  Subject: pythoncom and mshtml
>  
>  
>  I'm trying to use mshtml (i.e., the Microsoft HTML parser used in IE) from a
>  Python client, but as this is my first foray into using Python with COM (or on
>  Win32 for that matter), I'm having some difficulty.  I started by using makepy
>  on mshtml.tlb to create a wrapper.
>  
>  Here's a transcript from within the shell:
>  
>  >>> import win32com.client
>  >>> o = win32com.client.Dispatch('htmlfile')
>  >>> o
>  <win32com.gen_py.Microsoft HTML Object Library.DispHTMLDocument>
>  
>  This looks OK so far, AFAIK.  Now, the next step is to open a document.  The
>  python seems to recognize the method:
>  
>  >>> o.createDocumentFromUrl
>  <method DispHTMLDocument.createDocumentFromUrl of DispHTMLDocument instance at
>  01F10EDC>
>  
>  But when I try to actually use the method:
>  
>  doc = o.createDocumentFromUrl('192.168.1.1', None)
>  
>  a fault occurs inside mshtml.dll that kills pythonwin.       If I do this inside a
>  ..py file and wrap it in a 'try', it still kills pythonwin (or python, if I'm at
>  a prompt). 
>  
>  Am I doing something wrong?
>  
>  I'm using ActivePython build 202 on Win98 (4.10.2222).       Any help would be
>  appreciated.
>  
>  -- 
>  Dave Seidel
>  [EMAIL PROTECTED]
>  
>  
>  _______________________________________________
>  ActivePython mailing list
>  [EMAIL PROTECTED]
>  http://listserv.ActiveState.com/mailman/listinfo/activepython
>  
>  
>  
>  

-- 
Dave Seidel
[EMAIL PROTECTED]


_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython

Reply via email to