VBScript来检测Facebook IE窗口,按“赞"并关闭窗口 [英] VBScript to detect Facebook IE window, press Like and close the window
问题描述
我试图制作一个脚本来检测在Facebook上打开的IE窗口并点击赞"按钮. 假设我打开了10个IE.其中只有一个位于Facebook的页面上. 我希望我的脚本检测到该IE窗口,请单击以下按钮:
I tryed to make a script to detect the IE window that is opened on Facebook and hit the Like button. Let's say I have 10 IE opened. Only one of them is on a page on Facebook. I want my script to detect that IE window, click this button:
IE.Document.getElementById("pagesHeaderLikeButton")
(上面的按钮是赞"按钮)
(The above button is the Like button)
并关闭该IE窗口.
我试图通过以下方式获取该IE窗口:
I tryed to get that IE window by:
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
但这只会将我的VBscript设置为第一个打开的IE,而找不到Facebook窗口.
But this will only set my VBscript to the first opened IE and it will not find the Facebook window.
我尝试过:
Dim objInstances, item
Set objInstances = CreateObject("Shell.Application").windows
For Each item In objInstances
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
IE.Document.getElementById("pagesHeaderLikeButton").Click
End If
Next
但是我收到未定义子或函数"
But I get "Sub or function not defined"
推荐答案
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(wnd.Name,"Internet") Then
if InStr(wnd.Document.URL,"facebook.com") Then
Set IE2 = wnd
Exit For
End If
End If
Next
因此按下按钮将如下所示:
So to press the button will be like this:
Set Butlike = IE2.Document.getElementsByTagName("button")
For Each btn In Butlike
If btn.type = "submit" Then btn.Click()
Next
这篇关于VBScript来检测Facebook IE窗口,按“赞"并关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!