Excel VBA +,465332字节
注意:使用引用来
- Microsoft HTML对象库
- Microsoft Internet控件
- Microsoft脚本运行时
打高尔夫球:
Sub
接受所需类型的输入n
(名称的缩写)的完整例程,并将Variant/String
该名称的查询的第一个Google图像搜索结果输出glamour shot
到Internet Explorer窗口。
Sub g(n)
Set i=New InternetExplorer
l="google.nl/search?tbm=isch&q="&Replace(n," ","+")&"+glamour+shot"
For y=0To 2
i.navigate l
While i.readyState<4
DoEvents
Wend
j=0
Do Until InStr(1,l,IIf(y,"yp","res"))
j=j+1
Set x=i.document.getElementsByTagName(IIf(y,"img","a"))(j)
If y Then l=x.src Else l=x.href
Loop
Next
i.visible=1
End Sub
-2个字节,用于删除空格 If InStr(1, a.href, "imgres") Then
-2个字节用于更改.navigate (a.href)
为.navigate a.href
-27字节,用于减少for each a in ... if (...) then ... end if .. next
循环到do until ... loop
-10字节用于冷凝imgres
到res
和encrypted
至yp
-8字节用于去除initalizers为j
,k
并且假定清洁模块
-1字节用于更改google.com
为google.nl
-3个字节,用于替换Dim i as New ...
为Set i=New ...
-8个字节,用于删除SHDocVw.
类引用
-12个字节用于删除with i
块
-7个字节用于删除i.quit
-这会通过在后台打开Internet Explorer导致一些内存泄漏,因此建议您使用完整的非高尔夫版本,或者使用后通过任务管理器终止Internet Explorer任务
-6个字节用于i.navigate
移入帮助程序子例程h
-13字节用于Do Until ... Loop
移入辅助程序
通过j=0
移入辅助程序并删除,j
,,0
(x2)-2字节
-11个字节,用于转换为匿名立即窗口函数
-8个字节,用于减少辅助函数调用的for .. next
循环
-16字节,用于将Sheets(1)
图像对象的输出更改为通过InternetExplorer
对象显示
Ungolfed,1304字节
Option Private Module
Option Compare Text
Option Explicit
Option Base 0
Sub GlamourShot(ByVal name As String)
Dim ie As New SHDocVw.InternetExplorer, _
doc As MSHTML.HTMLDocument, _
link As String, _
j As Integer, _
k As Integer
With ie
On Error GoTo CloseIE #'prevents memory leak
Let .visible = True
Call .navigate("www.google.com/search?tbm=isch&q=" & _
Replace(name, " ", "+") & _
"+glamour+shot")
While .readyState <> READYSTATE_COMPLETE Or .Busy
VBA.DoEvents
Wend
Set doc = .document
Let j = 1
Do Until InStr(1, link, "imgres") > 0
Let link = doc.getElementsByTagName("a")(j).href
Let j = j + 1
Loop
Call .navigate(link)
While .readyState <> READYSTATE_COMPLETE Or .Busy
VBA.DoEvents
Wend
Let k = 1
Do Until InStr(1, link, "encrypted") > 0
Let link = doc.getElementsByTagName("img")(k).src
Let k = k + 1
Loop
With ThisWorkbook.ActiveSheet
Call .Range("A1").Select
Call .Pictures.Insert(link)
Call .Activate
End With
CloseIE:
Call .Quit
End With
End Sub
用法gif