#1
  1. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247

    Feedback wanted for my library.


    Howdy folks,
    My first new contribution to the python community for the year 2005, is a library to control Internet Explorer using python. I would really appreciate some feedback.

    Here's the article link: Controlling Internet Explorer with Python

    You'll need to:
    (a) Run Windows (sorry Mac and *NIX users).
    (b) Have IE installed (should be a given, if you pass (a))
    (c) Have python installed (I've tested with 2.2, 2.3 and 2.4)
    (d) Have PythonWin and win32all installed. (See my link above for where to get these, in case you don't already have them).

    As always, the code is released under BSD-style license, so feel free to modify it for your own projects. I've suggested some uses for this library and I'm sure you'll come up with other uses.

    Thanks in advance for reviewing the article/code.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Nice work with the article Scorp. Very concise and to the point though I also found the discusion on Early vs Late Binding intersting -- from a Python users perspective; I use a Mac . That said I'll give it a wiz on a Windows machine when I have the chance.

    Good work,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    543
    Rep Power
    24
    Very impressive!

    I downloaded the Win32 extensions for Python, downloaded the MFC DLL for Pythonwin (which was not included in the installation) and saved the file to my C:\WINDOWS\system32\ directory, extracted the IEC.zip file, and ran the demo.

    I am using Python 2.4 and Windows XP: Home Edition service pack 2.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    37
    Rep Power
    10

    Awesome!


    I am using windows XP Pro, PythonWin 2.3.3. The code works great and solved a big problem I was having! Very instructional for me as a newbie to see the code as well. Thanks again for a great tool!
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Very good job Scorpions. Your program really shows the wonderful things that Python can do.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    That's a nice wrapper - a good idea. I've seen COM control of IE before, but never thought of adding functionality like that.

    Comments:
    - I tried to navigate Google with it, and found that I had to use SetInputValue instead of SetTextArea to enter search text. I know they are different in HTML, but would another method, e.g. .SetText(name, value) which works on both be a good idea? That way, if you know the form element "name" is where you put your name, it doesn't matter how it's implemented...

    - "if window_num = 0. If window_num > 0, the class looks at the list of open Internet Explorer window, and attempts to hook to the one corresponding to window_num."

    Since Window_Num is fairly random, this could also be extended to iterate through the open IE windows, get the current URL and check it against a string, so you could hook into "the IE Window at file_submit.html", for instance. Something like:

    Code:
        def __FindOpenIE(self, URLString=None, window_num):
            # CLSID for ShellWindows
            clsid='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
            ShellWindows = Dispatch(clsid)
    
            if URLString:
                for ieWindow in ShellWindows:
                    if URLString in ieWindow.document.location:
                        return ieWindow
    
            else:
                if (ShellWindows.Count < 1 or window_num > ShellWindows.Count):
                return self.__CreateNewIE()
            else:
                return ShellWindows[window_num - 1]
    (Untested)

    - You've used ".lstrip().rstrip()" a few times - .strip() will do both sides at once.

  12. #7
  13. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Thanks for the feedback all. sfb -- I actually had some LocationURL code that I added, just before you posted. Good catch on the lstrip/rstrip. Guess that's what happens when you're coding half-asleep . I'll code the SetInput thingy later. The thing is that the TEXTAREA element requires you to set "OuterHtml" attribute, whereas the INPUT element requires you to set the "value" attribute. So you'll have to check the element type before deciding what to do with it. Should be fairly easy to code .
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo