创建了一个表单:
<form action="posting.php" method="post" name="post" onsubmit="return checkForm(this)">
当我将表单的数据发布到posting.php时,它会将我发回表单所在的页面。我尝试手动输入表单而没有填写字段,当页面中缺少某些内容时,它会在页面上显示错误消息,当我提交时,页面的HTML中没有这些消息(我将其打印到shell以查看它的位置)。
我尝试使用机械化但没有成功。
根据机械化的形式:
<TextControl(subject=)>
<TextControl(sub_title=)>
<HiddenControl(<None>=black) (readonly)>
<SelectControl(addbbcode18=[*#, darkred, red, orange, brown, yellow, green, olive, cyan, blue, darkblue, indigo, violet, white, black])>
<HiddenControl(<None>=12) (readonly)>
<SelectControl(addbbcode20=[7, 9, *12, 18, 24])>
<HiddenControl(<None>=:)) (readonly)>
<TextareaControl(message=)>
<HiddenControl(=) (readonly)>
<HiddenControl(mode=newtopic) (readonly)>
<HiddenControl(f=1521) (readonly)>
<HiddenControl(last_post=0) (readonly)>
<CheckboxControl(disable_bbcode=[on])>
<CheckboxControl(disable_smilies=[on])>
<CheckboxControl(notify=[*on])>>
我的发布代码(post_url是“domainname.posting.php”):
def post_data(url, values={}): #either read a page or post to a page
if values != {}: #if values were provided, post request
data = urllib.urlencode(values) #encode the valyes
req = urllib2.Request(url, data=data) #make the request
resp = urllib2.urlopen(req) #get the response
return resp.read() #return the read page
else: #no values, normal read request
req = urllib2.Request(url) #request the url
resp = urllib2.urlopen(req) #get the reponse
return resp.read() #return the read page
print post_data(post_url, {"subject":"Test Post","sub_title":"","message":"Test","<None>":"black", "addbbcode18":"black","<None>":12,"addbbcode20":"12","<None>":":","last_post":"0","disable_bbcode":"on","disable_smilies":"on","notify":"on",None:None,"mode":"newtopic","f":"1521"})
表单数据顺序是否需要匹配表单的顺序(如机械化所示)?也许我为表单提供了无效的值类型(例如“disable_bbcode”:“on”,如果它是“disable_bbcode”:“[* on]”?)。它可能是表单声明中的onsubmit,如果这是问题,我该如何提交呢?
注意: