Python clientform无法获取expexted resu

2024-06-16 12:23:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用关键字“现场音乐”搜索http://www.wegottickets.com/。但返回的结果仍然是主页面,而不是包含大量现场音乐信息的搜索结果页面。谁能告诉我问题出在哪里吗?在

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()

非常感谢!在


Tags: fromimportformcomhttp音乐responsewww
1条回答
网友
1楼 · 发布于 2024-06-16 12:23:41

从来没有用过它,但是如果python mechanize模块被证明是clientform中的一个错误,我已经成功地使用了python mechanize模块。在

不过,作为第一步,我建议删除你的尝试…除了包装。你所做的基本上就是说“捕捉任何错误,然后忽略实际错误并打印‘unsuccessfully Query’”。对调试没有帮助。如果你不碍事,这个异常将停止程序并打印一条有用的错误消息。在

相关问题 更多 >