自动化登录网站的过程

时间:2019-02-26 08:41:09

标签: javascript html forms url automation

我想每天自动执行登录网页的过程。 首先,我希望输入和提交我的凭据的过程能够自动正常运行,然后我将了解如何使其在cron作业或类似的工作中定期运行。

这是我要登录的页面的源代码:(https://customer.sunvalleytek.com/login

<html lang="en"><head>
<title>Sunvalley - Your Login | RAVPower, TaoTronics, HooToo, VAVA</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<!--
<meta http-equiv="Cache-Control" content="no-store"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">



<script async="" src="//www.googletagmanager.com/gtm.js?id=GTM-KC4S8Q"></script><script type="text/javascript">
var ctxPath = '';
var brand = 'RAVPower';
</script>
<!--[if lt IE 9]>
   <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
   <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<!-- Include the FontAwesome CSS if you want to use feedback icons provided by FontAwesome -->
<!--<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" />-->

<link rel="stylesheet" href="/css/bootstrap.css">
<link rel="stylesheet" href="/css/bootstrapValidator.min.css">
<link rel="stylesheet" href="/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="/css/styles.css?v=1.0">
<script src="/js/jquery-1.12.1.min.js"></script>
<script src="/js/bootstrap/bootstrap.min.js"></script>
<script src="/js/bootstrap/bootstrapValidator.js"></script>
<script src="/js/bootstrap/bootstrap-datetimepicker.js"></script>

<script src="/js/util.js"></script>
<script src="/js/jquery.blockUI.js"></script>
<script src="/js/i18n/front-lang-en.js"></script>
<script src="/js/front-base.js"></script>
<script src="/js/common.js"></script>
<link href="/images/favicon.ico" type="image/x-icon" rel="icon">
<link href="/images/favicon.ico" type="image/x-icon" rel="Shortcut Icon"><!--地址栏和标签上显示图标-->
<link href="/images/favicon.ico" type="image/x-icon" rel="Bookmark"><!--收藏夹显示图标-->

<script type="text/javascript">
	var pageValidate = {
		fields:{
			email: {
				validators:{
					notEmpty: {
	                    message: bootstrapValidatorMsg.required
	                },
					emailAddress: {
	                    message: bootstrapValidatorMsg.email
	                }
				}
			},
			password: {
				validators:{
					notEmpty: {
	                    message: bootstrapValidatorMsg.required
	                }
				}
			}
		}
	};
	var login = {
		forms:[{
			id:'loginForm',
			submit:true,
			url: '/noaccount/login',
			validate:pageValidate,
			confirmFn:function(rtmsg){
				var opt;
				if(rtmsg.SUCCESS){
					if(rtmsg.backto){
						window.location.href = ctxPath + rtmsg.backto;
					}else{
						window.location.href = ctxPath + "/account/welcome";
					}
				}else{
					$('#boxModalTitle').html(PromptMsg.prompt);
					$('#boxModalBody').html(rtmsg.MESSAGE);
					opt = function () {
					};

					$('#boxModal').modal('show');
					$('#boxModal').on('hide.bs.modal', opt);
				}
			}
		}]
	};


	var pageValidateResetPwd = {
		fields:{
			accountEmail: {
				validators:{
					/*notEmpty: {
	                    message: bootstrapValidatorMsg.required
	                },
					emailAddress: {
	                    message: bootstrapValidatorMsg.email
	                }*/
				}
			}
		}
	};


	var resetPwd = {
		forms:[{
			id:'resetPwdForm',
			submit:true,
			url: '/noaccount/password/reset',
			validate:pageValidateResetPwd,
			confirmFn:function(rtmsg){
				var opt;
				if(rtmsg.SUCCESS){
					$('#forgetPasswordModel').modal('hide');

					$('#boxModalTitle').html(PromptMsg.prompt);
					opt = function () {

					};
					$('#boxModalBody').html(rtmsg.MESSAGE);
					$('#boxModal').modal('show');
					$('#boxModal').on('hide.bs.modal', opt);
				}else{
					$('#msgTip').text(rtmsg.MESSAGE);
					$('#msgTip').show();
				}
			},
			beforeSendFn:function(){
				$('#msgTip').text("");
			}
		}]
	};

	$().ready(function(){
		bootValidate(login.forms);
		bootValidate(resetPwd.forms);
	});
</script>
</head>
<body>
	<!-- Google Tag Manager -->
	<noscript>&lt;iframe src="//www.googletagmanager.com/ns.html?id=GTM-KC4S8Q"
	height="0" width="0" style="display:none;visibility:hidden"&gt;&lt;/iframe&gt;</noscript>
	<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
	new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
	j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
	'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
	})(window,document,'script','dataLayer','GTM-KC4S8Q');</script>
	<!-- End Google Tag Manager -->

	<div class="container-fluid">
  		<div class="container">
    		<div class="row">
      			<div class="col-md-4 col-md-offset-4 login margin-t1">
        			<div class="logo">
          				<img src="/images/login-logo.png" class="img-responsive center-block">
        			</div>
        			<form role="form" id="loginForm" method="post" class="form-horizontal bv-form" novalidate="novalidate"><button type="submit" class="bv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
        				<input type="hidden" name="brandId" id="brandId" value="1">
        				<input type="hidden" name="preUrl" value="null">
        				<input type="hidden" name="backto" value="">
           				<h5>Your session has time out, please log in again.</h5>
           				<!-- email -->
           				<div class="form-group has-feedback">
             				<label class="control-label">Email :</label>
             				<input type="text" id="email" name="email" autocomplete="off" autofocus="autofocus" class="form-control" placeholder="enter your e-mail" data-bv-field="email"><i class="form-control-feedback" data-bv-icon-for="email" style="display: none;"></i>
           				<small class="help-block" data-bv-validator="notEmpty" data-bv-for="email" data-bv-result="NOT_VALIDATED" style="display: none;">This field is required.</small><small class="help-block" data-bv-validator="emailAddress" data-bv-for="email" data-bv-result="NOT_VALIDATED" style="display: none;">Invalid Email Address</small></div>
           				<!-- end email -->

           				<!-- password -->
           				<div class="form-group has-feedback">
           					<label class="control-label">Password :</label>
             				<input type="password" id="password" name="password" autocomplete="off" class="form-control" placeholder="confirm password" data-bv-field="password"><i class="form-control-feedback" data-bv-icon-for="password" style="display: none;"></i>
             				<a class="pull-right forget" href="#" data-toggle="modal" data-target="#forgetPasswordModel">Forget password</a>
           				<small class="help-block" data-bv-validator="notEmpty" data-bv-for="password" data-bv-result="NOT_VALIDATED" style="display: none;">This field is required.</small></div>
           				<!-- end password -->

           				<!-- sign -->
           				<div class="form-group text-center">
             				<button type="submit" class="btn blue-bg" data-toggle="modal">SIGN IN</button>
             				<a class="btn blue-bg" href="/noaccount/register/init?backto=&amp;utm_source=&amp;utm_medium=&amp;utm_campaign=">Register Now</a>
           				</div>
           				<!-- end sign -->
        			</form>
      			</div>
    		</div>
  		</div>
	</div>
	<!-- Modal -->
	<div class="modal fade" id="forgetPasswordModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
		<div class="modal-dialog">
			<div class="modal-content">
					<div class="modal-header">
  						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  						<h4 class="modal-title" id="myModalLabel">Forget your password?</h4>
					</div>
					<div class="modal-body">
						<p class="text-center">Please enter your email address below. Your will receive a link to reset your password.</p>
						<form role="form" id="resetPwdForm" method="post" class="form-horizontal bv-form" novalidate="novalidate"><button type="submit" class="bv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
    						<div class="form-group has-feedback">
      							<span id="msgTip" class="col-md-5 col-md-offset-3 col-sm-6 col-xs-9 red-color"></span>
      							<span class="col-md-5 col-md-offset-3 col-sm-6 col-xs-9">
        							<input type="text" class="form-control" id="accountEmail" name="accountEmail" autocomplete="off" placeholder="user@domain.com" data-bv-field="accountEmail"><i class="form-control-feedback bv-no-label" data-bv-icon-for="accountEmail" style="display: none;"></i>
      							</span>
      							<span class="col-md-2 col-sm-2 col-xs-3">
        							<button type="submit" class="btn org-bg">Submit</button>
      							</span>
    						</div>
  						</form>
					</div>
			</div>
		</div>
	</div>
	<!-- END modal -->

	<!-- modal box start-->
<div class="profile-modal">
	<div class="modal fade" id="boxModal" tabindex="-1" role="dialog" aria-labelledby="boxModalTitle" aria-hidden="true">
	     <div class="modal-dialog">
	       <div class="modal-content">
	         <div class="modal-header">
	           <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button>
	           <h4 class="modal-title" id="boxModalTitle"></h4>
	         </div>
	         <div class="modal-body">
	         	<div class="row">
	         		<div class="col-md-12">
		         		<h5 id="boxModalBody" style="margin-bottom:30px;"></h5>
		         	</div>
		         	<div class="form-group text-center">
		         		<span class="col-md-4 col-md-offset-4">
							<button type="button" class="btn org-bg" data-dismiss="modal">OK</button>
						</span>
					</div>
	         	</div>
			 </div>
	      </div>
	     </div>
	</div>
</div>
<!-- modal box end-->

</body></html>

我尝试使用POST方法(https://crunchify.com/automatic-html-login-using-post-method-autologin-a-website-on-double-click/)和此处概述的其他方法(https://help.risevision.com/hc/en-us/community/posts/115019363963-Auto-Login-on-Webpage-using-Javascript)自动使用HTML输入我的凭据,其中我将http://www.exemple.com的网址替换为{ {3}},但是它不起作用。 我的猜测是表单类型使用Javascript,而上面的链接概述了如何填充html类型表单。但是我还没有发现有关自动填充Javascript类型表格的任何信息。

任何帮助将不胜感激。 非常感谢。

0 个答案:

没有答案