tags:

views:

122

answers:

3

hello everyone .. can anyone help me with loop i want loop that code

login_form_data = urllib.urlencode(login_form_seq)
 opener = urllib2.build_opener()
 site = opener.open(B, login_form_data).read()

the code allow me to login to site but site have problem and the problem is: you can't login from first time

that mean I have to press submit then when page reload press submit again... so i think loop will do that but How!?

+2  A: 

You need to handle cookies. Look at the cookielib module.

Forrest
sir can you explain to me ? with code and comments #
Hamoud-Oz
+1  A: 

If it is a cookie handling problem, use the "HTTPCookieProcessor" in urllib2. By applying it to your opener.

cookieHandler = urllib2.HTTPCookieProcessor() # Needed for cookie handling

# Apply the handler to an opener
opener = urllib2.build_opener(cookieHandler)        
monkut
A: 

It seems that you are not accepting and saving the cookie(s) required by the page you are trying to access. This is not surprising given that urllib2 does not automatically do this for you. As others have said you'll have to explicitly write code to accept cookies. Something like this:

import urllib2, cookielib
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

login_form_data = urllib.urlencode(login_form_seq)
site = opener.open(B, login_form_data).read()

This would be a good time to read up about cookielib and HTTP state management in Python.

Manoj Govindan
well sir it's not depend on cookies so just tell me how to make it submit twice time !
Hamoud-Oz