我正尝试使用以下代码提交表单http://www.harshtechtalk.com/contact-us-harsh-tech-talk,但没有成功。请帮忙!无法在python中使用urllib2提交网页表单
#!C:/Python27/python.exe
import urllib
import urllib2
def main():
proxy_info={
'user' : '[email protected]',
'pass' : 'xyz',
'host' : 'xxxxxxxx',
'port' : 80
}
proxy_support = urllib2.ProxyHandler({"http" : "http://%(user)s:%(pass)[email protected]%(host)s:%(port)d"
% proxy_info})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
url = 'http://www.harshtechtalk.com/contact-us-harsh-tech-talk'
values = {
'your-name':'test_name',
'your-email':'[email protected]',
'your-subject':'python_test',
'your-message':'test_message'
}
data = urllib.urlencode(values)
req = urllib2.Request(url,data)
response = urllib2.urlopen(req)
the_page = response.read()
print "done"
if __name__ == '__main__':
main()
PS - 我不想使用“机械化”,因为它不支持JavaScript。请让我知道是否有任何其他模块可用于处理动态Web表单。
“不成功”是什么意思?你现在怎么执行JavaScript? – geoffspear
这是我博客上的联系表单。所以,对于任何表单提交,我收到一封电子邮件。没有成功,我的意思是我没有收到任何邮件。它使用机械化,因为我曾尝试使用它。所以,表单没有问题。 – theharshest