Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

python web form fill

Options
  • 26-03-2007 6:56pm
    #1
    Closed Accounts Posts: 247 ✭✭


    Hi,
    Im new to python (used to use perl) and i want to fill out a form on a site called easynews.com
    here it is in html


    [PHP] <td align=left valign=bottom nowrap>
    <form action="http://www.easynews.com/login/&quot; method=post name="login">
    <font face=arial size="+1"><u><b>MEMBERS LOGIN</b></u></font><br><br>
    <font face=arial size=-1>USERNAME:</font><br>
    <input type="text" name="username" size=15 maxlength=15><br>
    <font face=arial size=-1>PASSWORD:</font><br>
    <input type="password" name="password" size=15 maxlength=15><br>
    <input type="submit" value="login"><br>
    </form>
    </td>[/PHP]

    would i be right in saying this is a POST method?

    My python code looks like this but unfortunaley it doenst work!!

    [PHP]#!/usr/bin/python
    import urllib

    data = urllib.urlencode({"username" : "XXXXXX", "password" : "XXXXXXX"})
    f = urllib.urlopen("http://www.easynews.com",data)
    s = f.read()
    print s[/PHP]


    And neither does something similiar in perl!!
    Help appreciated!
    Ive googled this a lot and got nothing useful really
    Thanks


    aside - im not so sure about python - i mean does it seriously force you to start every line at the cursor position 0?


Comments

  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Hi,
    Im new to python (used to use perl) and i want to fill out a form on a site called easynews.com
    here it is in html


    [PHP] <td align=left valign=bottom nowrap>
    <form action="http://www.easynews.com/login/&quot; method=post name="login">
    <font face=arial size="+1"><u><b>MEMBERS LOGIN</b></u></font><br><br>
    <font face=arial size=-1>USERNAME:</font><br>
    <input type="text" name="username" size=15 maxlength=15><br>
    <font face=arial size=-1>PASSWORD:</font><br>
    <input type="password" name="password" size=15 maxlength=15><br>
    <input type="submit" value="login"><br>
    </form>
    </td>[/PHP]

    would i be right in saying this is a POST method?

    My python code looks like this but unfortunaley it doenst work!!

    [PHP]#!/usr/bin/python
    import urllib

    data = urllib.urlencode({"username" : "XXXXXX", "password" : "XXXXXXX"})
    f = urllib.urlopen("http://www.easynews.com",data)
    s = f.read()
    print s[/PHP]


    And neither does something similiar in perl!!
    Help appreciated!
    Ive googled this a lot and got nothing useful really
    Thanks


    aside - im not so sure about python - i mean does it seriously force you to start every line at the cursor position 0?

    This looks correct, more or less. What error message do you get?

    On your aside, what do you mean by start every line at the cursor position 0? It doesn't, certainly, although blocks must be indented correctly.


  • Closed Accounts Posts: 247 ✭✭because_I_can


    it doesnt give any error message- it just seems to ignore the data im posting to the form. I read the page after i submit the form into variable s.
    printing s then just results in the exact same page as without printing s.

    So it looks to me like the easynews server is looking for maybe a referrer or something. It doesnt like being filled out by a script i think, which would make sense.

    Now i was looking at this : http://www.mayukhbose.com/python/IEC/index.php

    and it looks like it will over come that problem as it essentially controls IE in the same way as i use my mouse keyb etc.

    Im just installing it now and the win32com libraries for python it needs but im having some problems.

    http://sourceforge.net/projects/pywin32/

    Apparently that needs python 2.6 but all i have is the 2.51 that comes with cygwin. And i cant find 2.6 anyplace online. In fact i dont even think its released yet from looking on python.org

    http://www.python.org/download/


    Maybe i'll get an older release of that python extensions and it should do. Very wierd why its asking for 2.6 though!


    Oh and im starting to like python. Its seems better than perl in terms of having lots of things included and no huge need to go messing around with modules etc.

    python to exe looks cool as well and it seems like python has lots of simple gui toolkits modern looking which beats perl hands down.

    Thanks!


Advertisement