How to fill a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sulsa

    How to fill a form

    I need to fill form from web site, the code for this form looks like
    this:

    <form action="login.p hp" method="post" target="_top">

    <input type="text" name="username" size="25" maxlength="40"
    class="post" />
    <input type="password" name="password" size="25" maxlength="25"
    class="post" />

    <input type="hidden" name="redirect"
    value="" />
    <input type="submit" name="login" class="mainopti on"
    value="Login" />

    </form>

    I can of course connect to a web site and download the form, i do it
    like this:

    import urllib2
    www = urllib2.urlopen ("http://www.site.com/login.php")
    form_data= stronka.read()

    or using httplib:

    import httplib
    conn = httplib.HTTPCon nection("www.si te.com")
    conn.request("G ET", "/login.php")
    data1 = conn.getrespons e().read()


    but i can't fill and send this form is there some simple way to do it?
  • Steve Holden

    #2
    Re: How to fill a form

    Sulsa wrote:
    I need to fill form from web site, the code for this form looks like
    this:
    >
    <form action="login.p hp" method="post" target="_top">
    >
    <input type="text" name="username" size="25" maxlength="40"
    class="post" />
    <input type="password" name="password" size="25" maxlength="25"
    class="post" />
    >
    <input type="hidden" name="redirect"
    value="" />
    <input type="submit" name="login" class="mainopti on"
    value="Login" />
    >
    </form>
    >
    I can of course connect to a web site and download the form, i do it
    like this:
    >
    import urllib2
    www = urllib2.urlopen ("http://www.site.com/login.php")
    form_data= stronka.read()
    >
    or using httplib:
    >
    import httplib
    conn = httplib.HTTPCon nection("www.si te.com")
    conn.request("G ET", "/login.php")
    data1 = conn.getrespons e().read()
    >
    >
    but i can't fill and send this form is there some simple way to do it?
    I'd recommend you take a look at mechanize, see



    and specifically at ClientForm, see



    These make it easy to perform browser-like accesses to forms-based web
    applications.

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden

    Comment

    • Sulsa

      #3
      Re: How to fill a form

      On Tue, 15 Aug 2006 03:22:40 +0100
      Steve Holden <steve@holdenwe b.comwrote:
      I'd recommend you take a look at mechanize, see
      >

      >
      and specifically at ClientForm, see
      >

      >
      These make it easy to perform browser-like accesses to forms-based
      web applications.
      >
      I want to fill only one smiple form so i would like not to use any non
      standard libraries.

      Comment

      • Grant Edwards

        #4
        Re: How to fill a form

        On 2006-08-15, Sulsa <sulsa@gazeta.p lwrote:
        I want to fill only one smiple form so i would like not to use
        any non standard libraries.
        Then just send the HTTP "POST" request containing the fields
        and data you want to submit.

        --
        Grant Edwards grante Yow! LBJ, LBJ, how many
        at JOKES did you tell today??!
        visi.com

        Comment

        • Steve Holden

          #5
          Re: How to fill a form

          Sulsa wrote:
          On Tue, 15 Aug 2006 03:22:40 +0100
          Steve Holden <steve@holdenwe b.comwrote:
          >
          >
          >>I'd recommend you take a look at mechanize, see
          >>
          > http://wwwsearch.sourceforge.net/mechanize/
          >>
          >>and specifically at ClientForm, see
          >>
          > http://wwwsearch.sourceforge.net/ClientForm/
          >>
          >>These make it easy to perform browser-like accesses to forms-based
          >>web applications.
          >>
          >
          >
          I want to fill only one smiple form so i would like not to use any non
          standard libraries.
          That's your choice, but frankly I'd be very surprised if it wasn't
          quicker to download and use mechanize/clientform than it was to put your
          own solution together.

          regards
          Steve
          --
          Steve Holden +44 150 684 7255 +1 800 494 3119
          Holden Web LLC/Ltd http://www.holdenweb.com
          Skype: holdenweb http://holdenweb.blogspot.com
          Recent Ramblings http://del.icio.us/steve.holden

          Comment

          • Sulsa

            #6
            Re: How to fill a form

            On Tue, 15 Aug 2006 03:37:02 -0000
            Grant Edwards <grante@visi.co mwrote:
            On 2006-08-15, Sulsa <sulsa@gazeta.p lwrote:
            >
            I want to fill only one smiple form so i would like not to use
            any non standard libraries.
            >
            Then just send the HTTP "POST" request containing the fields
            and data you want to submit.
            but i don't know how to post these data if i knew there there would
            be no topic.

            Comment

            • Tom Brown

              #7
              Re: How to fill a form

              On Monday 14 August 2006 20:43, Sulsa wrote:
              On Tue, 15 Aug 2006 03:37:02 -0000
              >
              Grant Edwards <grante@visi.co mwrote:
              On 2006-08-15, Sulsa <sulsa@gazeta.p lwrote:
              I want to fill only one smiple form so i would like not to use
              any non standard libraries.
              Then just send the HTTP "POST" request containing the fields
              and data you want to submit.
              >
              but i don't know how to post these data if i knew there there would
              be no topic.
              When I need to learn the POST method for a form, I use wireshark
              (www.wireshark.org) to capture the POST I do manually the first time.
              However, I think I'm going to look into mechanize/clientform now that I
              know about it.

              Hope this helps,
              Tom

              Comment

              • Yu-Xi Lim

                #8
                Re: How to fill a form

                Sulsa wrote:
                but i don't know how to post these data if i knew there there would
                be no topic.
                Source code: Lib/urllib/ urllib is a package that collects several modules for working with URLs: urllib.request for opening and reading URLs, urllib.error containing the exceptions raised by urlli...


                You want to look at urlopen and urlencode.

                But if you mean you don't know what fields and data to use, then you
                need a HTML reference, not a Python one.

                Comment

                • John J. Lee

                  #9
                  Re: How to fill a form

                  Sulsa <sulsa@gazeta.p lwrites:
                  On Tue, 15 Aug 2006 03:37:02 -0000
                  Grant Edwards <grante@visi.co mwrote:
                  >
                  On 2006-08-15, Sulsa <sulsa@gazeta.p lwrote:
                  I want to fill only one smiple form so i would like not to use
                  any non standard libraries.
                  Then just send the HTTP "POST" request containing the fields
                  and data you want to submit.
                  >
                  but i don't know how to post these data if i knew there there would
                  be no topic.
                  Something like this (UNTESTED, and I can never remember all the
                  details, which are fiddlier than they may look):

                  import urllib, urllib2
                  query = urllib.urlencod e([
                  ("username", "sulsa"), ("password", "sulsa"),
                  ("redirect", ""), ("login", "Login"),
                  ])
                  r = urllib2.urlopen ("http://example.com/login.php", query)
                  print r.read()


                  Note that urllib and urllib2 both, as their main job in life, open
                  URLs. urllib also has miscellaneous functions related to URLs &c. I
                  use urllib2 above because I know it better and because it can handle
                  some stuff that urllib doesn't (it's designed more for extensibility
                  than is urllib).


                  John

                  Comment

                  • Philippe Martin

                    #10
                    Re: How to fill a form

                    Sulsa wrote:
                    On Tue, 15 Aug 2006 03:37:02 -0000
                    Grant Edwards <grante@visi.co mwrote:
                    >
                    >On 2006-08-15, Sulsa <sulsa@gazeta.p lwrote:
                    >>
                    I want to fill only one smiple form so i would like not to use
                    any non standard libraries.
                    >>
                    >Then just send the HTTP "POST" request containing the fields
                    >and data you want to submit.
                    >
                    but i don't know how to post these data if i knew there there would
                    be no topic.
                    You forgot thanks and regards

                    Comment

                    • Justin Ezequiel

                      #11
                      Re: How to fill a form

                      Sulsa wrote:
                      On Tue, 15 Aug 2006 03:37:02 -0000
                      Grant Edwards <grante@visi.co mwrote:
                      >
                      On 2006-08-15, Sulsa <sulsa@gazeta.p lwrote:
                      I want to fill only one smiple form so i would like not to use
                      any non standard libraries.
                      Then just send the HTTP "POST" request containing the fields
                      and data you want to submit.
                      >
                      but i don't know how to post these data if i knew there there would
                      be no topic.


                      Comment

                      Working...