首页 新闻 搜索 专区 学院

关于正则表达式提取html页面内容

0
悬赏园豆:20 [已解决问题] 解决于 2017-01-07 13:51

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>用户登录 - 博客园</title>
<link href="/css/signin_bundle.css?v=bz_ySXODvfR4SvyE7zrsWqZTU1x7afVQLMhMPrSG6kw1" type="text/css" rel="stylesheet" />
<script src="//common.cnblogs.com/script/jquery.js"></script>
<script src="/scripts/jsencrypt.min.js"></script>
<script>
var return_url = 'https://www.cnblogs.com/';
var ajax_url = '/user' + '/signin';
var enable_captcha = false;
var is_in_progress = false;

function setFocus() {
document.getElementById('input1').focus();
}

function check_enter(event) {
if (event.keyCode == 13) {
var target = event.target || event.srcElement;
if (target.id == "input1") {
if (document.getElementById('input1').value == '') {
$('#tip_input1').html("请输入登录用户名");
return;
}
else if (document.getElementById('input2').value == '') {
document.getElementById("input2").focus();
return;
}
}
if (target.id == "input2") {
if (document.getElementById('input2').value == '') {
$('#tip_input2').html("请输入密码");
return;
}
}
signin_go();
}
}

function signin_go() {
if(is_in_progress){
return;
}

$('#tip_input1').html('');
$('#tip_input2').html('');

var input1 = $.trim($('#input1').val());
if (!input1) {
$('#tip_input1').html("请输入登录用户名");
$('#input1').focus();
return;
}
var input2 = $.trim($('#input2').val());
if (!input2) {
$('#tip_input2').html("请输入密码");
$('#input2').focus();
return;
}

if(enable_captcha)
{
var captchaCode = $.trim($('#captcha_code_input').val());
if (!captchaCode)
{
$('#tip_captcha_code_input').html("请输入验证码");
$('#captcha_code_input').focus();
return;
}
}

$('#tip_btn').html('提交中...');

var encrypt = new JSEncrypt();
encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB');
var encrypted_input1 = encrypt.encrypt($('#input1').val());
var encrypted_input2 = encrypt.encrypt($('#input2').val());
var ajax_data = {
input1: encrypted_input1,
input2: encrypted_input2,
remember: $('#remember_me').prop('checked')
};

if(enable_captcha){
var captchaObj = $("#captcha_code_input").get(0).Captcha;
ajax_data.captchaId = captchaObj.Id;
ajax_data.captchaInstanceId = captchaObj.InstanceId;
ajax_data.captchaUserInput = $("#captcha_code_input").val();
}
is_in_progress = true;
$.ajax({
url: ajax_url,
type: 'post',
data: JSON.stringify(ajax_data),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
headers: {
'VerificationToken': 'H9AbbvV7mQ55U3EBSqsXIH0uNhLXXelkd3wRhKujyOON0Hfgxjm52x5YYxG-rGNmFBBfWp4SRi_ZxU31N7zHSy50ong1:Zd2a9-dvNjUY4vaAIrto0kuuOxxTQN-kwvUzxMi_Mvwu4xAmQj0nS_t2LLvshIlvzSG4QxyXAKFhq-ELBsrnCBetG0M1'
},
success: function (data) {
if (data.success) {
$('#tip_btn').html('登录成功,正在重定向...');
location.href = return_url;
} else {
$('#tip_btn').html(data.message + "<br/><br/>联系 contact@cnblogs.com");
is_in_progress = false;
if(enable_captcha)
{
captchaObj.ReloadImage();
}
}
},
error: function (xhr) {
is_in_progress = false;
$('#tip_btn').html('抱歉!出错!联系 contact@cnblogs.com');
}
});
}

$(function () {
$('#signin').bind('click', function () {
signin_go();
}).val('登 录');

});
</script>
</head>
<body onload="setFocus()">
<div style="width: 100%;">
<div align="center">
<div id="Main">
<noscript>
<div style="font-size:15px;margin-bottom:20px;">
您的浏览器未启用Javascript,无法进行登录。
</div>
<style>
form { display:none;}
</style>
</noscript>
<form method="post" onsubmit="return false;">
<div id="Heading">登录博客园 - 代码改变世界</div>
<div class="block">
<label class="label-line">登录用户名(<a href="/GetUsername.aspx" tabindex="-1" class="tb_right">找回</a>)</label>
<input type="text" id="input1" value="" class="input-text" onkeydown="check_enter(event)" /> <span id="tip_input1" class="tip"></span>
</div>
<div class="block">
<label class="label-line">密码(<a href="/GetMyPassword.aspx" tabindex="-1" class="tb_right">重置</a>)</label>
<input type="password" id="input2" value="" class="input-text" onkeydown="check_enter(event)" /> <span id="tip_input2" class="tip"></span>
</div>
<div class="block">
<input id="remember_me" type="checkbox" name="remember_me" onkeydown="check_enter(event)" /><label for="remember_me" onkeydown="check_enter(event)">下次自动登录</label>
</div>
<div class="block">
<input type="submit" id="signin" class="button" value="加载中..." /> <span id="tip_btn" class="tip"></span>
</div>
<div class="block nav">
&raquo; <a href="/register.aspx?ReturnUrl=https://www.cnblogs.com/" title="注册成为博客园用户">立即注册</a><br />
&raquo; <a href="http://www.cnblogs.com/ContactUs.aspx">反馈问题</a>
</div>
</form>
<div style="clear: both" />
</div>
</div>
</div>
</body>
</html>

 

 

 

上边是html页面的字符串,如何提取其中的'VerificationToken': 'H9AbbvV7mQ55U3EBSqsXIH0uNhLXXelkd3wRhKujyOON0Hfgxjm52x5YYxG-rGNmFBBfWp4SRi_ZxU31N7zHSy50ong1:Zd2a9-dvNjUY4vaAIrto0kuuOxxTQN-kwvUzxMi_Mvwu4xAmQj0nS_t2LLvshIlvzSG4QxyXAKFhq-ELBsrnCBetG0M1'我加了下划线的内容 ,因为正则也是刚用过几次,提取了几次总是出问题

hayhx的主页 hayhx | 初学一级 | 园豆:2
提问于:2017-01-07 13:41
< >
分享
最佳答案
0

试试这个正则表达式

'VerificationToken':\s*'(.*?)'

 

收获园豆:20
dudu | 高人七级 |园豆:39033 | 2017-01-07 13:49

谢谢,基本可以了  谢谢

hayhx | 园豆:2 (初学一级) | 2017-01-07 13:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册