天天看點

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

}

});

}

}