首先,我登录www.example.com/login网站,结果网站包含如下脚本:
<script type="text/javascript">
$(function () {
if ($('#UserLocationGroup option').size() <= 1) {
$('#UserLocationGroup').attr("disabled", "disabled");
}
$('#UserLocationGroup').change(function () {
var areYouSure = true;
if ($('form').length > 0) {
areYouSure = $('form').triggerHandler('navigateaway');
}
if (areYouSure === false) {
return;
}
$.post('/Users/set-role', $.extend({}, { id: $(this).val() }, aw.antiforgeryToken), function (data, textStatus, xhr) {
console.log('redirecting..' + data.redirectUrl);
});
});
});
$(document).ready(function () {
if ($("#UserLocationGroup > option").length == 1) {
$("#UserLocationGroup").css("background-image", "none");
}
var usernameWithTrim = $('.js-tooltip-admin');
var usernameWithoutTrim = $('.js-tooltip-light-admin');
if (usernameWithoutTrim.width() <= usernameWithTrim.width()) {
usernameWithoutTrim.hide();
}
});
并且有下拉菜单,其中包含option1 option2 option3,当选项发生变化时,上面的js开始向服务器发送帖子(至少这是我的理解)
我如何从robobrowser模仿这篇文章?
我试过了
browser=RoboBrowser()
headers={'X-Requested-With': 'XMLHttpRequest','User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36'}
browser.session.headers.update(headers)
print browser.response.headers
data={'id':role,'__RequestVerificationToken':token}
encoded_data=urllib.urlencode(data)
browser.session.request( 'POST', 'https://example.com/Users/set-role',encoded_data,标头)
并且此操作失败,没有详细信息错误,
任何人都可以帮忙吗?
答案 0 :(得分:0)