views:

45

answers:

0
import urllib2, cookielib
import ClientForm
from BeautifulSoup import BeautifulSoup

    first_name = "Jonas"
    last_name = "Carlsson"

    '''request url'''
    url = 'http://www.ratsit.se/BC/Search.aspx'
    cookiejar = cookielib.LWPCookieJar()
    cookiejar = urllib2.HTTPCookieProcessor(cookiejar)

    opener = urllib2.build_opener(cookiejar)
    urllib2.install_opener(opener)

    response = urllib2.urlopen(url)
    forms = ClientForm.ParseResponse(response, backwards_compat=False)

    form = forms[0]
    print form.__dict__



    controls = form.__dict__.get('controls')
    print "------------------------------------------------------------"
    try:

        '''here is to submit the value to form'''

        controls[1] = first_name
        controls[2] = last_name

        page = urllib2.urlopen(form.click('ctl00$cphMain$cmdButton')).read()

       '''something wrong with the click here, and can not pass value to form'''


        print '----------here-------'
        soup = BeautifulSoup(''.join(page))
        soup = soup.prettify()

    except Exception, e:
        print 'The following error occured: \n"%s"' % e