79254066

Date: 2024-12-05 09:38:28
Score: 1
Natty:
Report link

As your present code. I'm develop an EXCEL XLSM file with this code and tested. Its resulted is OK. Please try. Do not forget to apply references "Microsoft HTML Object Library" and "Microsoft XML. v6.0"

Sub scrapeimageurls()
On Errors GoTo paigon

Dim website As String
Dim IE As InternetExplorer
Dim html As HTMLDocument
Dim ElementCol As Object, Link As Object
Dim erow As Long
Dim dn, dm, dx  As Long
Dim imu As String

Application.ScreenUpdating = False

website = "https://ss.ge/ka/udzravi-qoneba/iyideba-4-otaxiani-bina-saburtaloze-3872071"

Set IE = New InternetExplorer
    IE.Visible = False
    IE.navigate website

Do While IE.readyState <> READYSTATE_COMPLETE
    Application.StatusBar = "Trying to go to website…"
Loop

Set html = IE.document
Set ElementCol = html.getElementsByTagName("img")

dm = 100000  'Set Lower limit of file size in Mb
For Each Link In ElementCol
    If InStr(1, Link.src, ".jpg") > 0 Then
        imu = Link.src
        dx = FileSize(imu)
        If dx > dm Then            
            erow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
            ActiveSheet.Cells(erow, 2).Value = imu
            ActiveSheet.Cells(erow, 1).Value = dx
            dn = dn + 1
            'If dn = 10 Then Exit For 'Use this line if you need only 10 images file
        Else
        End If
    Else
    End If
Next

paigon:
IE.Quit
ActiveSheet.Cells(1, 1) = "IE Quit yet."
Application.StatusBar = ""
End Sub


Function FileSize(sURL As String) 'This function from "Jonas". Thanks to Jonas.
'https://stackoverflow.com/questions/53394257/excel-get-dimensions-and-filesize-from-jpg-url
Dim oXHTTP As Object
Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "HEAD", sURL, False
oXHTTP.send
If oXHTTP.Status = 200 Then
    FileSize = oXHTTP.getResponseHeader("Content-Length")
    Else
    FileSize = -1
End If
End Function
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Maimee Maima