从IE复制随机生成的文本

时间:2014-11-22 13:30:11

标签: internet-explorer text vbscript copy

目前我正在开发vbs,它可以打开网页,输入登录信息,登录,输入一些信息,然后收到随机生成的CD密钥。

有什么办法可以复制这张CD钥匙吗?使用ie.document.getelementbyid我无法找到任何与CD密钥相关的ID,只能使用包含CD密钥的整个文本框。

有没有办法准确指定网页上我想要的位置?就像从网站上的行中选择我要复制的文本一样?

CD密钥始终是随机的。唯一不变的是它将在一个单元格中,它有连字符(就像任何CD键一样)

我只需要提取CD密钥,以便将其存储在文本文件等中,如下例所示

Example

编辑:

到目前为止

代码:

Set IE = CreateObject("InternetExplorer.Application") 
 IE.Visible = 1    
 IE.navigate "xxxx" 
 Do While (IE.Busy)    
     WScript.Sleep 100    
 Loop    
 Set Helem = IE.document.getElementByID("UserNameTextBox") 
 Helem.Value = "xxxxx"    
 Set Helem = IE.document.getElementByID("PasswordTextBox")
 Helem.Value = "xxxxx"   
 Set Helem = IE.document.getElementByID("Button1")
 Helem.Click
 Do While (IE.Busy)    
     WScript.Sleep 100    
 Loop  
Set Helem = IE.document.getElementByID("generateECodes_PackageDropdown")
Helem.Value = "430"
IE.Document.getElementByID("generateECodes_PackageDropdown").FireEvent ("onChange")
WScript.Sleep 500
 Do While (IE.Busy)    
     WScript.Sleep 500    
 Loop  
Set Helem = IE.document.getElementByID("generateECodes_TermDropdown")
Helem.Value = "5"
IE.Document.getElementByID("generateECodes_TermDropdown").FireEvent ("onChange")
 Do While (IE.Busy)    
     WScript.Sleep 500    
 Loop  
Set Helem = IE.document.getElementByID("generateECodes_Languages")
Helem.Value = "29"
IE.Document.getElementByID("generateECodes_Languages").FireEvent ("onChange")
 Do While (IE.Busy)    
     WScript.Sleep 500    
 Loop  
Set Helem = IE.document.getElementByID("generateECodes_StoreNumber")
Helem.Value = "230"
IE.Document.getElementByID("generateECodes_StoreNumber").FireEvent ("onChange")
 Do While (IE.Busy)    
     WScript.Sleep 500    
 Loop  
 Set Helem = IE.document.getElementByID("generateECodes_Required")
 Helem.Value = "1" 
 Do While (IE.Busy)    
     WScript.Sleep 500    
 Loop  
 Set Helem = IE.document.getElementByID("generateECodes_Button")
 Helem.Click
 Do While (IE.Busy)    
     WScript.Sleep 500    
 Loop  
   Set Helem = IE.document.getElementByID("generateECodes_Table")


 Do While (IE.Busy)    
     WScript.Sleep 100    
 Loop  

dim filesys, filetxt, getname, path 
Set filesys = CreateObject("Scripting.FileSystemObject") 
Set filetxt = filesys.CreateTextFile("c:\Something.txt", True) 
path = filesys.GetAbsolutePathName("c:\Something.txt") 
getname = filesys.GetFileName(path) 
filetxt.WriteLine("Password: "+Helem) 
filetxt.WriteLine("Brugernavn: "+Helem) 
filetxt.Close 

1 个答案:

答案 0 :(得分:1)

枚举您已提取的表中的<td>元素,并检查innerText是否与CD密钥的模式匹配:

...
Set Helem = IE.document.getElementByID("generateECodes_Table")

Set re = New RegExp
re.Pattern = "\w{5}(-\w{5}){4}"
re.IgnoreCase = True

For Each td In Helem.getElementsByTagName("td")
  If re.Test(td.innerText) Then cdKey = td.innerText
Next
...