3 Replies - 2338 Views - Last Post: 10 March 2010 - 05:47 PM Rate Topic: -----

#1 Guest_Gretty*


Reputation:

Python Script to Get Webpage Info Not Working

Posted 10 March 2010 - 04:04 PM

Hello

I am asking what is probably a very easy thing to do but I cannot find a tutorial on how to do it anywhere. I want to use a Python script to get information from a webpage.

I found a semi Python & internet tutorial here if anyone else would like it http://www.upriss.or...n/session6.html

I would like to create a python script that gets a value from a set of radio buttons on a HTML page & tell me which one is selected.

I have 3 radio buttons: Tea, Coffee, Hot Chocolate & a Submit button

My script is meant to find which radio button is selected & tell me that. But it just keeps saying "No Drink Selected!"

Can you help me figure out how to fix this. FYI: My Python script & my HTML page are both saved in the same directory. And I made the webpage using Notepad++, I open the webpage in Interent Explorer & I made the Python Script in Idle.

Python Script:
# Practice 9 CGI

######### don't change the following three lines: ###########
import cgi
print("Content-Type: text/html\n")
form = cgi.FieldStorage()

## add a form.getvalue for each of the names in your form: ##
drink = form.getvalue("drink")

########## start of HTML code ###########
print(""" 
<html>
<head> <title>What would you like to drink</title> </head>
<body>
<h4>Your drink: </h4><p>
""")
############ end of HTML code #############

if drink == "tea":
    print("You requested tea.")
elif drink == "coffee":
    print("You requested coffee.")
elif drink == "hot chocolate":
    print ("You requested hot chocolate.")
else:
    print ("You need to select a drink!")

########### start of HTML code ###########
print (""" 
<p>Thank you for your visit. Please come again. <p>
</body></html>
""")
############# end of HTML code ##############



HTML Code:
<html>
<head>


</head>

<body>

<form action="practice9.py" method="post"> 

<input type="radio" name="drink" value="tea" checked > Tea <br> 
<input type="radio" name="drink" value="coffee" > Coffee <br> 
<input type="radio" name="drink" value="hot chocolate" > Hot Chocolate <p> 

<input type="submit" value="Place order"> 
</form> 


</body>
</html>


Is This A Good Question/Topic? 0

Replies To: Python Script to Get Webpage Info Not Working

#2 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: Python Script to Get Webpage Info Not Working

Posted 10 March 2010 - 05:00 PM

Are you running a CGI-enabled HTTPd?
Was This Post Helpful? 0
  • +
  • -

#3 Guest_gretty*


Reputation:

Re: Python Script to Get Webpage Info Not Working

Posted 10 March 2010 - 05:39 PM

I am very new to this. What do you mean by CGI-enabled HTTPd? How would I run it?
Was This Post Helpful? 0

#4 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: Python Script to Get Webpage Info Not Working

Posted 10 March 2010 - 05:47 PM

In order to run CGI scripts, you need a web server.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1