hotmail

Bertrand Geston bergeston at yahoo.fr
Thu Mar 7 12:58:07 EST 2002


Seems to be magic, thanks for the question and for the response. Really
interesting.
I would like to retrieve mails from Hotmail and I wonder if it is not
'better' to use COM/DOM on Outlook express that can, if I am not mistaken,
retrieve mails from Hotmail using http requests. By 'better', I mean less
linked to the hotmail site layout (but OK linked to the Oultook DOM
interface) and probably quicker.

Any thought, idea, code snippets ?

TIA.

B.

<brueckd at tbye.com> wrote in message
news:mailman.1015102571.6690.python-list at python.org...
> On Fri, 1 Mar 2002, Cameron Laird wrote:
>
> > >> im just wondering whether it is possible to access hotmail thru
python
> > >> so that i have a far quicker way of checking my emails. can telnetlib
> > >> do this?
> > >
> > >If you're on Windows (and have either ActiveState Python or Mark
Hammond's
> > >win32all extensions) then you can use COM to create a web browser
instance
> > >and use its DOM interface to navigate. I made a small script to
retrieve
> > >my address book this way - I'll try to dig it up and post it, but it's
> > >pretty easy to do from scratch too.
> > >
> > >-Dave
> >
> > I'd like to see this.
>
> I don't know what I did with the original version I wrote, so I
> rewrote it. I don't know if I'm doing everything by the "officially
> correct" methods, but it works great. Here you go:
>
> '''
> Example of using InternetExplorer COM/DOM interfaces to
> retrieve your Hotmail address book.
>
> Dave Brueck
> '''
>
> import win32com.client, time
>
> def WaitForDoc(ie):
>     'Return the document once it is loaded'
>     while ie.Busy: time.sleep(0.1)
>     doc = ie.Document
>     while doc.readyState != 'complete': time.sleep(0.1)
>     return doc
>
> def ClickOn(ie, text):
>     'Follow a link and return the resulting doc'
>     for link in ie.Document.Links:
>         if link.href.find(text) != -1:
>             link.Click()
>             break
>     return WaitForDoc(ie)
>
> # Start up a browser
> ie = win32com.client.Dispatch('InternetExplorer.Application.1')
> ie.Visible=0 # Change to 1 to see it in action
> ie.Navigate('http://www.hotmail.com')
> doc = WaitForDoc(ie)
>
> # Fill in the username and password
> doc.All('login').Value = 'USERNAME' # Insert your own here
> doc.All('passwd').Value = 'PASSWORD' # Ditto
> doc.Forms[0].Submit()
>
> # Click on the Address Book link
> doc = WaitForDoc(ie)
> doc = ClickOn(ie, 'addresses')
>
> # Find the correct table
> doc = WaitForDoc(ie)
> table = doc.getElementsByName('ListTable')[0]
>
> # Extract the rows (spruce up as needed)
> rows = table.rows
> for i in range(rows.length):
>     cells = rows[i].cells
>     for j in range(cells.length):
>         print cells[j].innerText, '|',
>     print
>
> # Logout
> doc = ClickOn(ie, 'logout')
> doc = WaitForDoc(ie)
>
>
>





More information about the Python-list mailing list