472,977 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,977 software developers and data experts.

how to use the form submit..

i was trying to figure out the form.click() function and dont have a clue on how to implement it. can someone please help me? say by sending the search form in google (or something like that)?
Jul 20 '07 #1
5 3392
bartonc
6,596 Expert 4TB
i was trying to figure out the form.click() function and dont have a clue on how to implement it. can someone please help me? say by sending the search form in google (or something like that)?
You post lacks specificity. There are many way/modules that you might be using.
Please be specific with your question and tell us (or better, post some code) what tools that you are using. Thanks.
Jul 20 '07 #2
well urllib2 + ClientForm


Expand|Select|Wrap|Line Numbers
  1. from urllib2 import urlopen
  2. from ClientForm import ParseResponse
  3.  
  4. response = urlopen("http://google.com")
  5. forms = ParseResponse(response)
  6. form = forms[0]
  7. print form
  8. form["q"] = "dogs"
  9.  
  10. # form.click() returns a urllib2.Request object
  11. # (see HTMLForm.click.__doc__ if you don't have urllib2)
  12. print urlopen(form.click()).read()

that is what im trying to work with. i keep getting an error 403 though.. i think that is because it doesnt save cookies. someone on these forums said something about a module that sends and recieves cookies invisibly and automatically, but i searched and found nothing.
Jul 21 '07 #3
bartonc
6,596 Expert 4TB
well urllib2 + ClientForm


Expand|Select|Wrap|Line Numbers
  1. from urllib2 import urlopen
  2. from ClientForm import ParseResponse
  3.  
  4. response = urlopen("http://google.com")
  5. forms = ParseResponse(response)
  6. form = forms[0]
  7. print form
  8. form["q"] = "dogs"
  9.  
  10. # form.click() returns a urllib2.Request object
  11. # (see HTMLForm.click.__doc__ if you don't have urllib2)
  12. print urlopen(form.click()).read()

that is what im trying to work with. i keep getting an error 403 though.. i think that is because it doesnt save cookies. someone on these forums said something about a module that sends and recieves cookies invisibly and automatically, but i searched and found nothing.
That's funny: the 2.5 docs have documentation of the Cookie Module and the cookielib Module. I'd love to be able to help you further, but I'm not a web guy.
Jul 21 '07 #4
That's funny: the 2.5 docs have documentation of the Cookie Module and the cookielib Module. I'd love to be able to help you further, but I'm not a web guy.
oh well i didnt know which to use because someone said that the module laid invisibly over urllib2 to automatically deal with the cookies. i think that cookielib does that... i couldnt get cookielib, all i could dig up was cookie. and i guess it would be good for you to know that i am working with 2.4 port.

but now i dont think that that is the problem since google search doesnt require cookies (i think). I tried out cookielib, and still get the 403 Forbidden error. maybe to do with the headers... well i got it to work with yahoo, but i sort of need this to work too.
Jul 22 '07 #5
Linksterman,
I think I have figured out the problem. I am by no means a python developer, actually downloaded the installer today and started on the same thing you were working on, and ran into your same problem. Any way, what I found was the User-agent header needs to be set, once set google is ok with the search request. I would like to do a wire trace to compare HTTP streams but at least it works.

from urllib2 import urlopen
from ClientForm import ParseResponse

response = urlopen("http://google.com")
forms = ParseResponse(response)
form = forms[0]
print form
form["q"] = "dogs"

# ....updated code below this line....
request2 = form.click() # urllib2.Request object
request2.add_header('User-agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.1.4322)')
response2 = urllib2.urlopen(request2)


print "HTTP Code:"
print response2.code
print response2.info() # headers


Please note, the top portion of the inital HTTP GET was slightly different so the code may not work as exact, please use as a guide.

Phil
Aug 1 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p...
2
by: Matt | last post by:
Can form.submit() submit another form? In the following example, in page1.asp, it is fine to submit the current form: form1.submit(), and and I could see the value "Joe" in page2.asp. However, if I...
2
by: Terence Parker | last post by:
How does one go about submitting a form with a link - but submitting it to a new window AND to a page different to that described within the action="" option of the <form> tag? Say, for example,...
4
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM:...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
6
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.