1

I've written a script in vba to download different movie posters from a torrent site and embed them in a spreadsheet right next to its concerning movies. My script can parse the movie names in a spreadsheet and download & save the images in a folder. What I can't do is place the downloaded images next to each movie name in a spreadsheet.

How can I place the movie posters in concerning cells right next to each movie name?

My script so far:

Sub DownloadAndEmbedImages()
    'customized directory location within double quotes
    Const strPath$ = "C:\Users\WCS\Desktop\Test\"
    Dim Http As New XMLHTTP60, Html As New HTMLDocument
    Dim post As Object, imgArr As Variant, R&

    'check out if the folder is empty. If not empty, delete them to download anew
    If Dir(strPath & "*.*") <> "" Then Kill strPath & "*.*"

    With Http
        .Open "GET", "https://yts.am/browse-movies", False
        .send
        Html.body.innerHTML = .responseText
    End With

    For Each post In Html.getElementsByClassName("img-responsive")
        R = R + 1: Sheets("Sheet1").Cells(R, 1) = post.alt
        imgArr = Split(post.src, "/")
        imgArr = imgArr(UBound(imgArr) - 1) & ".jpg"

        Http.Open "GET", post.src, False
        Http.send

        With CreateObject("ADODB.Stream")
            .Open
            .Type = 1
            .write Http.responseBody
            .SaveToFile (strPath & imgArr)
            .Close
        End With
    Next post
End Sub

Referenece to add to execute the above script:

Microsoft XML, v6.0
Microsoft HTML Object library
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
MITHU
  • 113
  • 3
  • 12
  • 41

0 Answers0