天天看点

python实现网页表单填写_python在网页中自动填充表单

我试图填写一个网页,有一个单一的文本框和一个发送按钮的html看起来像这样

Send

我尝试使用mechanize提交带有此代码的表单

^{pr2}$

代码运行时没有错误,但是没有提交,我该怎么做?在

这是SendMessage函数function SendMessage() {

var text = $('#Text').val();

var userId = $('#RecipientId').val();

if (text.trim() === "")

{

$('#TextContainer').css('border-color', 'red');

}

else if (new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_][email protected])?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?").test(text))

{

$('#TextContainer').css('border-color', 'red');

$('#message').html("Links are not allowed in messages");

}

else

{

$('#Send').button('loading');

$.ajax(

{

url: '/Messages/SendMessage',

type: 'POST',

cache: false,

data:

{

__RequestVerificationToken: $('').attr('value'),

userId: userId,

text: text

}

});

}

}