请问如何用vba实现自动登陆账号密码,访问宁稳网网页?
网页链接如下(没有账号只能看到错误提示):
https://www.ninwin.cn/index.php?m=cb&a=cb_all&show_cb_only=Y&show_listed_only=Y
由于没有账号只能看到错误提示,我把网页源码的head部分贴在下面了,我猜负责登录的可能是其中script代码。我是需要构造一段script脚本,把用户名和token提交send给服务器做验证吗?
具体怎么写代码?
感谢解答!
PS:我仅有使用CreateObject("InternetExplorer.Application")和CreateObject("MSXML2.XMLHTTP.3.0")的基本经验。。。
<link href="https://www.ninwin.cn/themes/site/default/css/dev/forum.css?v2=3&v=2019012111750" rel="stylesheet" />
<link href="public/require/mystyle.css?v=2019012111750" rel="stylesheet" />
<script src="res/js/dev/jquery.js?v=2019012111750">script>
<script src="public/require/js/ajax.min.js?v=2019012111750">script>
<script src="public/require/js/myfun.min.js?v2=5&v=2019012111750">script>
<script src="public/require/js/cb/pop_card.min.js?v2=6?v2=3&v=2019012111750">script>
<script>
var FID = '';
Wind.use("global",function(){//此部分需提前到cbAjax加载之前,否则cbAjax会找不到global.js
if(!isMobile){
var q_url=location.protocol + '//' + location.host + '/index.php?m=cb&c=question&a=checkQuestion';
$.post(q_url,
function(data){
data=JSON.parse(data);
//console.log(data);
if(!data.question){
Wind.Util.alert({
id : "wind_dialog_alert_2",
top : 200,
left: 600,
msg :data.msg,
});
}
}
);
}
//无内容 发帖引导
Wind.js(GV.JS_ROOT + 'pages/bbs/postGuide.js?v=' + GV.JS_VERSION);
});
script>
可以通过VBA模拟登录该网站。以下是一个简单的VBA示例,它使用Internet Explorer自动完成登录并访问指定网页。
Sub LoginToWebsite()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
'Navigate to the login page
ie.Navigate "https://www.ninwin.cn/index.php?m=cb&a=cb_all&show_cb_only=Y&show_listed_only=Y"
'Wait for the page to load
Do While ie.Busy Or ie.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
'Fill in the login form
ie.Document.getElementById("username").Value = "your_username"
ie.Document.getElementById("token").Value = "your_token"
ie.Document.forms(0).submit
'Wait for the page to load
Do While ie.Busy Or ie.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
'Navigate to the target page after logging in
ie.Navigate "https://www.ninwin.cn/target_page"
'Wait for the page to load
Do While ie.Busy Or ie.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
'Do something on the target page
'...
'Close Internet Explorer
ie.Quit
End Sub
在这个示例中,您需要将“your_username”和“your_token”替换为您自己的用户名和token。代码中使用的是Internet Explorer对象来模拟登录和浏览网页。在填写登录表单之后,您可以导航到目标网页并执行其他操作。最后,关闭Internet Explorer对象以结束会话。
请注意,这是一个非常简单的示例,可能需要根据您的具体情况进行修改。您可能需要检查网页源代码以查找要填写的表单元素和提交的URL。