0

I have the following script to logon to a url,but on submit in the webpage i call

<input type=button value="go"  onclick="Search()";>

How to do the same in the following script instead of submit......

import urllib, urllib2, time
username = "sumname"
password = "test"
interval = 10
data = {"username":username,"password":password,"submit":"sign in"}
value = urllib.urlencode(data)
request = urllib2.Request("http://127.0.0.1/accounts/login/",value)
print "request="%request
#while (1):
open = urllib2.urlopen(request)
response = open.read()
response=str(response)
print response

Thanks...

1 Answer 1

2

urllib and urllib2 are not the best ways to simulate browser interaction! You should rather be looking at mechanize (which does plug into urllib2). It's possible to simulate such interaction on "bare" urllib2, but it's just too much work and fragility to bother;-).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Alex........urlib2 served my purpose in this case.....I got a script that is finally working....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.