各位大佬们,小弟遇上的问题是这样的:
我想用java爬点我们公司上的数据:现在目前的实现代码是这样的:
try {
URL url = new URL("http://192.168.10.17:8080/xxxx");//小弟就不暴露公司网址了哈
URLConnection uconn = url.openConnection();
uconn.setDoOutput(true);
uconn.connect();
String temp;
final StringBuffer sb = new StringBuffer();
final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(),"utf-8"));
while ((temp = in.readLine())!= null){
sb.append("\n");
sb.append(temp);
}
in.close();
System.out.println(sb);
}catch (Exception e){
System.out.println("出错啦");
}
}
运行时,没有报错。控制台的打印显示但跳到了登录页面:
(即网页源码:)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<title></title>
<link href="/" type="text/css" rel="stylesheet">
</head>
<body>
<div class="loing_logo">
<!-- 登录页面logo的替换 -->
<img src="/wuche/static/portal/goodsMaster/images/logo1.png">
</div>
<div class="login">
<div class="message">欢迎登录</div>
<div id="darkbannerwrap"></div>
<form method="post">
<input type="text" maxlength="11" id="phone_login" placeholder="请输入手机号">
<hr class="hr15">
<input type="password" id="password_login" placeholder="请输入密码">
<hr class="hr15">
<input value="登录" type="button" id="login" style="width:100%;" >
<hr class="hr20">
<a href="/wuche/f/frontUser/toFindPassword" >忘记密码</a>
<a style="margin-left: 160px;" href="/wuche/f/frontUser/toUserReg">没有账号?免费注册</a>
<p></p>
</form>
</div>
</body>
<script type="text/javascript" src="/wuche/static/portal/motorcade/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="/wuche/static/portal/motorcade/layui/layui.js"></script>
<script src="/wuche/static/portal/common/common.js"></script>
<script src="/wuche/static/portal/common/regular.js"></script>
<script type="text/javascript">
$("#login").click(function() {
var phone = $.trim($("#phone_login").val());
var password = $.trim($("#password_login").val());
if (!isEmpty(phone, '手机号不能为空') || !checkPhone(phone, '手机号格式不正确')) return;
if (!isEmpty(password, '密码不能为空')) return;
$.ajax({
url : /f/frontUser/login',
async : false,
type : "POST",
data : {
"phone" : phone,
"password" : password
},
dataType : "json",
success : function(date) {
if (date.code == '1') {
setTimeout(
function() {
location.href = '/f/sys/user/userInfo';
}, 500);
} else {
showMsg(date.msg);
}
}
});
});
//注册
$("#resiter").click(function(){
location.href = '//f/frontUser/todriverReg';
});
//enter事件登录
document.onkeydown=function(event){
var e = event || window.event || arguments.callee.caller.arguments[0];
if(e && e.keyCode==13){ // enter 键
var phone = $.trim($("#phone_login").val());
var password = $.trim($("#password_login").val());
if (!isEmpty(phone, '手机号不能为空') || !checkPhone(phone, '手机号格式不正确')) return;
if (!isEmpty(password, '密码不能为空')) return;
$.ajax({
url : '/f/frontUser/login',
async : false,
type : "POST",
data : {
"phone" : phone,
"password" : password
},
dataType : "json",
success : function(date) {
if (date.code == '1') {
setTimeout(
function() {
location.href = '/wuche/f/sys/user/userInfo';
}, 500);
} else {
showMsg(date.msg);
}
}
});
} }
</script>
</html>
我可以在后台填入本应在前台网页input框的内容并触发在前端网页上的点击登录方法吗?还望各路大神教导小弟一下,感激不尽。