2012-11-30 312 views
0

我需要一个朋友的自动登录的工作,但我不能完成它,我不能使用文本框的ID插入文本,试图自动登录电子网站

调试器说: “未将对象引用设置为对象的实例”

你能告诉我我做错了什么或者如何解决它吗?

enter image description here

这是形式:

Public Class Form1 

    'Dim WebBrowser1 As New WebBrowser 
    Dim elm 
    Public Sub searchbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchbutton.Click 

     'WebBrowser1.Document.GetElementById("id_username").SetAttribute("value", "yourusernamehere") 
     WebBrowser1.Document.GetElementById("id_username").InnerText = "yourusernamehere" 

    End Sub 

    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     'WebBrowser1.Navigate("http://www.planetromeo.com/") 
     WebBrowser1.Navigate("http://www.planetromeo.com/main/login.php") 

    End Sub 

End Class 

这是HTTP://网站... /主/ login.php中来源:

<body class="pgLe" id="pgLeLo"> 
<div id="head"> <h1>Inicio de sesión</h1></div> 
<div id="loginWindow"> 
    <form method="post" action="https://www.planetromeo.com" name="login" target="_top" onsubmit="return submithandler()"> 
    <input type="hidden" name="PHPSESSID" value="wLzgSbXmdg7Goi1VYDiaXc4Hs4PV71gs" /> <input type="hidden" name="salt" id="id_salt" value="8547695" /> 
    <input type="hidden" name="resX" id="id_resX" value="" /> 
    <input type="hidden" name="resY" id="id_resY" value="" /> 
    <input type="hidden" name="secure" id="id_secure" value="" /> 
    <input type="hidden" name="initCallSec" id="id_initCallSec" value="0" /> 

    <div id="loginBox"> 
    <div class="spacer" style="height:9px;padding:0"></div> 
    <div class="inputBox"> 
     <input type="text" name="username" value="" id="id_username" size="12" maxlength="70" class="textbox" onchange="document.forms['login'].erinnern.checked=false" /><br /> 
     <label for="id_username">Nombre del perfil</label> 
    </div> 
    <div class="inputBox"> 
     <input type="password" name="passwort" value="" id="id_password" size="12" maxlength="20" class="textbox" onchange="document.forms['login'].secure.value=''" /><br /> 
     <label for="id_password">Contraseña</label> 
    </div> 
    <div id="statusBox"> 
     <select name="status" id="status" class="textbox"> 
       <option value="-1">Como última vez</option> 
     <option value="2">Charlar</option><option value="6">Amigos</option><option value="1">Nada</option><option value="3">Relación</option><option value="4">Cita</option><option value="7">Sexo</option><option value="8">Ocupado</option><option value="0">Ausente</option><option value="5">Invisible&nbsp;(Plus)</option>  </select> 
    </div> 
    <div class="checkerBox"> 
     <input type="checkbox" name="erinnern" value="1" id="id_erinnern" class="checkbox" /><label for="id_erinnern"><a href="../service/kontakthilfe/keyword_suche.php?helpid=166" onclick="return openUrl(this.href)">Recordar</a></label> 
    </div> 
    <div class="checkerBox"> 
     <input type="checkbox" name="jugendfrei" value="1" id="jugendfrei" class="checkbox" /><label for="jugendfrei"><a href="../service/kontakthilfe/keyword_suche.php?helpid=167" onclick="return openUrl(this.href)">Sin XXX</a></label> 
    </div> 
    <div> 
     <input type="submit" value="Entrar" class="button" /> 
    </div> 
    </div> 
    <div id="infoBox"> 
    <a href="https://www.planetromeo.com//00000000000000000000000000000000/service/login/" target="mitte">¿Olvidaste tu contraseña?</a><br /> 
      <a href="https://www.planetromeo.com" target="_top">Activar SSL</a> 
     </div> 
    </form> 
</div> 

这是http:// site ... com来源:

<!DOCTYPE html> 
<html> 
<head> 
<meta name="apple-itunes-app" content="app-id=404386888" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><title>PlanetRomeo</title> 
<script type="text/javascript"> 

function switchLanguage(lang) { 
    var frm = frames['oben'].document.forms['jump']; 
    frm.lang.value = lang; 
    frm.submit(); 
    return false; 
} 

</script> 

    <meta name="keywords" content="planetromeo,romeo,community,chat,men,kontakte" /> 
    <meta name="description" content="Online community and dating service for men. Free registration and search." /> 
     <link rel="apple-touch-icon-precomposed" href="/v1/img/touch-icon.png" /> 
</head> 



<frameset cols="*,796,*" framespacing="0" border="0" frameborder="0"> 
<frame name="links" src="/00000000000000000000000000000000/main/left.php" scrolling="no" noresize="noresize" /> 
<frameset rows="58,*" framespacing="0" border="0" frameborder="0"> 
<frame name="oben" src="/00000000000000000000000000000000/main/top.php" marginwidth="0" marginheight="0" scrolling="no" noresize="noresize" /> 
<frameset cols="116,680" framespacing="0" border="0" frameborder="0"> 
    <frame name="persoenliches" src="/main/login.php" marginwidth="0" marginheight="0" scrolling="no" noresize="noresize" /> 
    <frame name="mitte" src="/00000000000000000000000000000000/main/index.php" marginwidth="0" marginheight="0" scrolling="auto" noresize="noresize" /> 
</frameset> 
</frameset> 
    <frame name="heartbeat" src="/00000000000000000000000000000000/main/right.php" scrolling="no" noresize="noresize" /> 

    <noframes> 
    <h1></h1> 
    <p>Online community and dating service for men. Free registration and search.</p> 
    <p>Sorry, frame support needed!</p> 
    <a href="/00000000000000000000000000000000/main/top.php">Menu</a><br /> 
    <a href="/00000000000000000000000000000000/main/index.php">Main Page</a> 
    </noframes> 

</frameset> 


</html> 
+0

直接加载框架不起作用。首先加载主页,然后框架,恐怕我不经常使用webbrowsers或网站的框架,所以我不知道这个 – Steve

+0

Thankyou评论的原因,但你能告诉我你的意思是什么“加载框架”?我加载主页时没有加载框架?那么我怎么可以加载一个框架? – ElektroStudios

+0

在您的发布代码中,在form1.load中,您可以导航到http://www.planetromeo.com/main/login.php,这是边栏中的框架。如果您尝试在浏览器中打开该网址,则该网址为空白,除非您已经访问过该网页。清除Cookies或打开私人浏览标签,然后自己尝试 – Steve

回答

1

本文提出一个不同的语法...

http://vbcity.com/blogs/jatkinson/archive/2009/12/12/programmatically-entering-and-data-using-the-webbrowser-control.aspx

例如

昏暗usernameTextBox作为的HtmlElement = Me.mainWebBrowser.Document.All.Item( “电子邮件”)
usernameTextBox.InnerText = “james.t.atkinson”

但对于按钮

我。 mainWebBrowser.Document.GetElementById(“signIn”)。InvokeMember(“click”)

+0

Thankyou这么多,但我收到相同的错误使用您的示例:Dim usernameTextBox As HtmlElement = WebBrowser1.Document.All.Item(“id_username”) usernameTextBox.InnerText =“test”“Object reference没有设置为对象的实例“ – ElektroStudios

+0

嗯,我同意userXXXX现在它似乎与Frames有关。 – MatthewMartin