2013-01-08 95 views
4

我发现这个脚本在线,我编辑了大部分。VBScript启动网站登录

它能够输入用户名和密码,但无法点击登录。

请帮我修复 这里是登录论坛。

http://desistream.tv/en/index.shtml 

这里是脚本目前它在IE浏览器,但我需要改变它在谷歌浏览器打开。

WScript.Quit Main 

Function Main 
    Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_") 
    IE.Visible = True 
    IE.Navigate "http://desistream.tv/en/index.shtml" 
    Wait IE 
    With IE.Document 
    .getElementByID("login_username").value = "myusername" 
    .getElementByID("login_password").value = "mypassword" 
    .getElementByID("form").submit 
    End With 
End Function 

Sub Wait(IE) 
    Do 
    WScript.Sleep 500 
    Loop While IE.ReadyState < 4 And IE.Busy 
    Do 
    WScript.Sleep 500 
    Loop While IE.ReadyState < 4 And IE.Busy 
End Sub 

Sub IE_OnQuit 
    On Error Resume Next 
    WScript.StdErr.WriteLine "IE closed before script finished." 
    WScript.Quit 
End Sub 

回答

3

这里是......

Call Main 

Function Main 
    Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_") 
    IE.Visible = True 
    IE.Navigate "http://desistream.tv/en/index.shtml" 
    Wait IE 
    With IE.Document 
     .getElementByID("username").value = "myusername" 
     .getElementByID("pass").value = "mypassword" 
     .getElementsByName("frmLogin")(0).Submit 
    End With 
End Function 

Sub Wait(IE) 
    Do 
    WScript.Sleep 500 
    Loop While IE.ReadyState < 4 And IE.Busy 
End Sub 
+0

谢谢,如果帐户已经登录,我该如何添加条件?因为它提示错误。 – Mowgli

+1

很高兴看到我不会忘记一切,因为我最后一次网页脚本是在10年前:) 网站规则不允许在一个主题中有多个问题,所以如果你愿意的话可以打开新的主题,并且可能会得到更好的回复,但我的简短回复是 - 仅在登录时检查该页面上可用的html元素,并检查是否存在该元素,并仅在需要时才开始登录。 –

+0

至于在谷歌浏览器中这样做,你不能没有自动扩展。看到这个线程[链接](http://stackoverflow.com/questions/87911/tool-framework-for-automated-web-app-testing-in-google-chrome-browser),或只是谷歌“谷歌铬浏览器自动化”。 –

1

如果你看一下页面的源代码,你会看到实际<form>标签被称为frmLogin,不login

+0

非常感谢,我看着DIV ID论坛上,不能形成名字,非常感谢。 – Mowgli

+0

我有问题,如果帐户已经登录,我该如何使它不提示错误?谢谢 – Mowgli