Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now
12 of 31 removed with i block

Excel VBA +, 465 463 461 437 427 419 418 415 407 395 Bytes

Subroutine that takes input name of type string, searches for a glamour shot of that name on google images, navigates to that image and then outputs the image to the Sheets(1) object via the https://encrypted-tbn0.gstatic.com/images?q= - type link.

Must be run in a clean module.

NOTE: Uses References to

  • Microsoft HTML Object Library
  • Microsoft Internet Controls
  • Microsoft Scripting Runtime

Golfed:

Sub g(n)
Set i=New InternetExplorer
i.navigate "google.nl/search?tbm=isch&q="&Replace(n," ","+")&"+glamour+shot"
h i
Set d=i.document
Do Until InStr(1,l,"res")
j=j+1
l=d.getElementsByTagName("a")(j).href
Loop
i.navigate l
h i
Do Until InStr(1,l,"yp")
k=k+1
l=d.getElementsByTagName("img")(k).src
Loop
Sheets(1).Pictures.Insert l
i.quit
End Sub

Helper subroutine

Sub h(i)
While i.readyState<4
DoEvents
Wend
End Sub

-2 bytes for removing white space in If InStr(1, a.href, "imgres") Then

-2 bytes for changing .navigate (a.href) to .navigate a.href

-27 bytes for reducing for each a in ... if (...) then ... end if .. next loop to do until ... loop

-10 bytes for condensing imgres to res and encrypted to yp

-8 bytes for removing initalizers for j, k and assuming clean module

-1 byte for changing google.com to google.nl

-3 bytes for replacing Dim i as New ... with Set i=New ...

-8 bytes for removing SHDocVw. class reference

-12 bytes for removing with i block

Ungolfed, 674 Bytes:

Sub GlamourShot(ByVal name As String)

    Dim ie As New SHDocVw.InternetExplorer
    With ie

        Call .Navigate("www.google.com/search?tbm=isch&q=" & _
                Replace(name, " ", "+") & "+glamour+shot")
        While .ReadyState <> READYSTATE_COMPLETE
            DoEvents
        Wend

        For Each a In .document.getElementsByTagName("a")

            If InStr(1, a.href, "imgres") Then

                Call .navigate(a.href)

                While .ReadyState <> READYSTATE_COMPLETE
                    DoEvents
                Wend

                Dim link As String, _
                    index As Integer
                Let index = 1

                Do Until InStr(1, link, "encrypted") > 0
                    Let link = .document.getElementsByTagName("img")(index).src
                    Let index = index + 1
                Loop

                Call [A1].Select
                Call ActiveSheet.Pictures.Insert(link)
                Exit For
            End If
        Next

        Call .Quit

    End With
End Sub

Very poor quality gif

Usage Gif