views:

69

answers:

1

I am trying to search through http://www.wegottickets.com/ with the keywords "Live music". But the returned result is still the main page, not the search result page including lots of live music information. Could anyone show me out what the problem is?

from urllib2 import urlopen
from ClientForm import ParseResponse

response = urlopen("http://www.wegottickets.com/")
forms = ParseResponse(response, backwards_compat=False)
form = forms[0]
form.set_value("Live music", name="unified_query")
form.set_all_readonly(False)
control = form.find_control(type="submit")
print control.disabled
print control.readonly
#print form

request2 = form.click()
try:
    response2 = urlopen(request2)
except:
    print "Unsccessful query"

print response2.geturl()
print response2.info()
print response.read()
response2.close()

Thank you very much!

A: 

Never used it, but I've had success with the python mechanize module, if it turns out to be a fault in clientform.

However, as a first step, I'd suggest removing your try...except wrapper. What you're basically doing is saying "catch any error, then ignore the actual error and print 'Unsuccessful Query' instead". Not helpful for debugging. The exception will stop the program and print a useful error message, if you don't get in its way.

Lee B
Thank you for your answer. I just removed the "try...expect..." and I found a stupid mistake: I forgot to import urllib2...
pounds
:) easily done.
Lee B
Oh, p.s.: as a general rule, never catch exceptions apart from those you actually care about and have a specific way to handle. If you're reading a file, and are aware that this file might be missing (read the docs for read() and it should warn you that a FileNotFound exception may be thrown), then you can decide you want to catch that particular problem and handle it. Other problems should be left for those who care. They are usually functions futher up the call stack (e.g., main() may want to catch KeyBoardInterrupt, rather than handle it in a low level read_file() function).
Lee B