过帐表单数据失败

2024-04-26 01:27:23 发布

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

有一个表单是用以下内容创建的:

<form action="posting.php" method="post" name="post" onsubmit="return checkForm(this)">

当我将表单的数据发布到posting.php时,它会将我发送回表单所在的页面。我尝试在没有填写字段的情况下手动输入表单,当缺少某些内容时,它会在页面上包含一条错误消息,而在提交表单时,该错误消息不在页面的HTML中(我将其打印到shell以查看它的位置)

我试过使用mechanize,但没有成功

根据mechanize的表格:

<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\u 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"})

表单数据顺序是否需要与表单的顺序匹配(如mechanize所示)?可能我为表单提供了无效的值类型(“disable \u bbcode”:“on”例如,应该是“disable \u bbcode”:“[*on]”?)。它可能是表单声明中的onsubmit,如果这是一个问题,我如何提交它呢

注意事项:

  • 在打印出来的html中,“subject”和“message”的值是空的,所以我猜这些值永远不会被发布
  • 我怀疑“mode”和“f”是GET方法,但是当我尝试发布到“posting.php?mode=newtopic&;时;f=1521“(从公布的值中去掉“mode”和“f”),我得到相同的结果

Tags: thenoneurl表单readdatareturnon