使用vb.net填写自动Web表单 [英] automatic web form filling with vb.net

查看:111
本文介绍了使用vb.net填写自动Web表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免费的微软Word 插件让我疯狂。 Iam尝试使用Web浏览器控件和GetElementById方法通过vb.net填写html表单。



在博客主页上,当我尝试登录时,我必须填写用户名,passowrd然后单击提交按钮。在查看页面的HTML源代码时,我得到以下元素:





the free microsoft word plugin is driving me nuts. Iam trying to fill html forms through vb.net using web browser control and GetElementById method.

On blogger home page when i try to login, i have to fill user name, passowrd and then click on submit button. When viewing the HTML source of the page, i get the elements as :


<big></big><h2>Sign in to use Blogger<br> with your Google Account</br></h2>
<div class="input-holder"><label for="Email">Username (Email):</label>
<input type="text" size="10" name="Email" id="Email" class="text" dir="ltr" tabindex="1"></input></div>
<div class="input-holder"><label for="Passwd">Password:
(<a href="http://www.blogger.com/forgot.g" title="Forgot your password?">?</a>)</label>
<input type="password" size="10" tabindex="2" name="Passwd" id="Passwd" class="text" autocomplete="off" dir="ltr"></input></div>
<div id="PersistentCookie-holder"><input type="checkbox" name="PersistentCookie" id="PersistentCookie" tabindex="3" value="yes">

<label for="PersistentCookie">Remember me</label>
(<a href="http://help.blogger.com/bin/answer.py?answer=42054" target="_top" title="What is "remember me"?">?</a>)</input></div>
<div id="signin-btn-holder"><script type="text/javascript">
  document.write("\x3cspan id\x3d\x22signin-btn\x22 class\x3d\x22ubtn\x22 onclick\x3d\x22if (this.className.indexOf(\x26quot;ubtn-disabled\x26quot;) \x3d\x3d -1) {var e \x3d document[\x26#39;login\x26#39;].ok;(e.length) ? e[0].click() : e.click(); if (window.event) window.event.cancelBubble \x3d true; return false;}\x22\x3e\x3cspan class\x3d\x22left\x22\x3e\x3cspan\x3e\x26nbsp;\x3cimg src\x3d\x22/img/blank.gif\x22 width\x3d\x221\x22 height\x3d\x221\x22 alt\x3d\x22\x22\x3e\x26nbsp;\x3c/span\x3e\x3c/span\x3e\x3cspan class\x3d\x22i\x22\x3e\x3ca href\x3d\x22javascript:void(0)\x22 tabindex\x3d\x224\x22 onclick\x3d\x22return false;\x22\x3eSign in\x3c/a\x3e\x3c/span\x3e\x3cspan class\x3d\x22right\x22\x3e\x3cspan\x3e\x26nbsp;\x3cimg src\x3d\x22/img/blank.gif\x22 width\x3d\x221\x22 height\x3d\x221\x22 alt\x3d\x22\x22\x3e\x26nbsp;\x3c/span\x3e\x3c/span\x3e\x3c/span\x3e");
</script>
<script type="text/javascript">
  document.write("\x3cinput type\x3d\x22submit\x22 id\x3d\x22signin-btn-hidden\x22 name\x3d\x22ok\x22 value\x3d\x22Sign in\x22 tabindex\x3d\x22-1\x22 style\x3d\x22position:absolute; display:block; width:0; padding:0;                z-index:-1; border:none; top:-5000px; left:-5000px\x22\x3e");
</script>
<noscript><input type="submit" id="signin-btn-ns" class="ubtn ubtn-inline" name="ok" tabindex="4" value="Sign in"></input></noscript></div>
<div class="r"></div>







所以我按他们的ID获取元素,现在我的代码是:






so i get the elements by their id and now my code is :

<big>WebBrowser1.Document.GetElementById("Email").SetAttribute("value", "amit.tcet")
            WebBrowser1.Document.GetElementById("Passwd").SetAttribute("value", "151100151105")
            WebBrowser1.Document.GetElementById("signin-btn-ns").InvokeMember("click")</big>





但按钮未点击,因此我无法登录。



任何想法有什么问题?



but the button is not clicked and hence i cannot login.

any ideas what is wrong?

推荐答案

我在这里做了类似的事情。



这里 [< a href =http://www.codeproject.com/KB/web-security/Prevent_attacks.aspxtarget =_ blanktitle =New Window> ^ ]



或尝试下面这样的事情。





I have done a similar like this here.

Here[^]

or try something like following.


mshtml.HTMLDocument obj;
obj=(mshtml.HTMLDocument)WebBrowser1.Document;
obj.getElementById("signin-btn-ns").click();


这篇关于使用vb.net填写自动Web表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆