经典VBS操作记住免得丢了

'----------用鼠标抓网页元素***(子皮作品)-----------
'----------大家继续修改哈!!增加更多功能------------
'本意是想动态获得鼠标处网页源码,可惜VBS中不知道怎么实现,高手可以继续改
'JS我不太懂,置顶不完善,JS高手可以改更酷一点的发上来,呵呵

WebNumberx = 1:Allie = ""
Set SHApp = CreateObject("Shell.Application")
For Each SHWin In SHApp.Windows
If LCase(Right(SHWin.FullName, 12)) = "iexplore.exe" Then
Allie = Allie & WebNumberx & ") " & SHWin.locationname & vbcrlf
WebNumberx = WebNumberx + 1
End if
Next
Set SHApp = Nothing

ca = InputBox(Allie,"请输入要抓的网页编号","")

WebNumberx = 1
Set SHApp = CreateObject("Shell.Application")
For Each SHWin In SHApp.Windows
If LCase(Right(SHWin.FullName, 12)) = "iexplore.exe" Then
If WebNumberx = Int(ca) Then Set x = SHWin:Exit For
WebNumberx = WebNumberx + 1
End if
Next
Set SHApp = Nothing

Set WMI=GetObject("WinMgmts:")
Set Objs=WMI.InstancesOf("Win32_Process")
i = 1
For Each Obj In Objs
If LCase(Obj.name) = "iexplore.exe" Then
If i = Int(ca) Then x_pid = obj.ProcessID:Exit For
i = i + 1
End if
Next
Set Objs = Nothing:Set WMI = Nothing

CreateObject("WScript.Shell").AppActivate x_pid, False
Wsh.sleep 300

While x.busy or x.readystate<>4:wsh.sleep 100:Wend

Set v = x.document.createElement("div")
v.setAttribute "id","xxx"
v.setAttribute "value",""
v.setAttribute "type","hidden"
x.Document.appendChild(v)

Set v = x.document.createElement("div")
v.setAttribute "id","yyy"
v.setAttribute "value",""
v.setAttribute "type","hidden"
x.Document.appendChild(v)


js = js & "function mousePosition(ev){" & vbCrLf
js = js & "if(ev.pageX || ev.pageY){" & vbCrLf
js = js & "return {x:ev.pageX, y:ev.pageY};" & vbCrLf
js = js & "}" & vbCrLf
js = js & "return {" & vbCrLf
js = js & "x:ev.clientX + document.body.scrollLeft - document.body.clientLeft," & vbCrLf
js = js & "y:ev.clientY + document.body.scrollTop - document.body.clientTop" & vbCrLf
js = js & "};" & vbCrLf
js = js & "}" & vbCrLf
js = js & "function mouseMove(ev){" & vbCrLf
js = js & "ev = ev || window.event;" & vbCrLf
js = js & "var mousePos = mousePosition(ev);" & vbCrLf
js = js & "document.getElementById('xxx').value = mousePos.x;" & vbCrLf
js = js & "document.getElementById('yyy').value = mousePos.y;" & vbCrLf

js = js & "}" & vbCrLf

js = js & "document.onmousemove = mouseMove;" & vbCrLf

x.Document.parentWindow.execScript js, "javascript"

set oIE = WScript.CreateObject("InternetExplorer.Application","Event_")
With oIE
.MenuBar = 0
.StatusBar = 0
.AddressBar = 0
.ToolBar = 0
.Height = 410
.Width = 300
.Navigate "about:blank"
.Visible = 1
.Document.Write "<HTML><script language='javascript'>"
.Document.Write "function move(){if (window.screenLeft*2 > window.screen.width){window.moveTo(0,window.screen.height-410);}"
.Document.Write "else window.moveTo(window.screen.width-300,window.screen.height-410);}"
.Document.Write "function top(){setInterval('document.body.focus()',10);}"
'function top(){window.focus();setTimeout('top()',10);}
.Document.Write "top();</script>"
.Document.Write "<BODY οnmοuseοver='move()' scroll='no'>x: <input id='input1'><br>"
.Document.Write "y: <input id='input2'><br><BUTTON id='btn'>复制</BUTTON><br>"
.Document.Write "源码: <textarea id='input3' style='WIDTH:270px;Height:250px' size='6'></textarea><br>"
.Document.Write "</BODY></HTML>"
End With

Set oIE.Document.getElementById("btn").OnClick = GetRef("aaa")

Do
oIE.Document.getElementById("input1").value = x.Document.getelementbyid("xxx").Value
oIE.Document.getElementById("input2").value = x.Document.getelementbyid("yyy").Value

Set ym = x.Document.selection
If Not (ym Is Nothing) Then
Set ymm = ym.createRange
If Not (ymm Is Nothing) Then
If ymm.htmlText <> oIE.Document.getElementById("input3").value then
oIE.Document.getElementById("input3").value = ymm.htmlText
End if
End If
End If
Set ym = Nothing:Set ymm = nothing
wsh.sleep 20
Loop

Sub aaa
Set IE=CreateObject("InternetExplorer.Application")
IE.Navigate("about:blank")
IE.document.parentwindow.clipboardData.SetData "text",oIE.Document.getElementById("input3").value
IE.Quit
Set IE = nothing
End Sub

Sub Event_OnQuit
Set oIE = Nothing: Set x = Nothing
WScript.Quit
End Sub

WebNumberx = 1:Allie = ""
Set SHApp = CreateObject("Shell.Application")
For Each SHWin In SHApp.Windows
If LCase(Right(SHWin.FullName, 12)) = "iexplore.exe" Then
Allie = Allie & WebNumberx & ") " & SHWin.locationname & vbcrlf
WebNumberx = WebNumberx + 1
End if
Next
Set SHApp = Nothing

ca = InputBox(Allie,"请输入要抓的网页编号","")

WebNumberx = 1
Set SHApp = CreateObject("Shell.Application")
For Each SHWin In SHApp.Windows
If LCase(Right(SHWin.FullName, 12)) = "iexplore.exe" Then
If WebNumberx = Int(ca) Then Set x = SHWin:Exit For
WebNumberx = WebNumberx + 1
End if
Next
Set SHApp = Nothing

Set WMI=GetObject("WinMgmts:")
Set Objs=WMI.InstancesOf("Win32_Process")
i = 1
For Each Obj In Objs
If LCase(Obj.name) = "iexplore.exe" Then
If i = Int(ca) Then x_pid = obj.ProcessID:Exit For
i = i + 1
End if
Next
Set Objs = Nothing:Set WMI = Nothing

===============================

这里都是获取 IE 的信息的,这样写脚本太罗嗦了吧~ 就不能一次搞定?


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值