473,480 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to use the form submit..

38 New Member
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 3400
bartonc
6,596 Recognized Expert Expert
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
linksterman
38 New Member
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 Recognized Expert Expert
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
linksterman
38 New Member
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
scaph01
1 New Member
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
5740
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
5535
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
73344
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
7765
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
6537
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
3065
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
9280
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
8390
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
17670
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
10762
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
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.