(Solved) – How to Extract the src Name data scraping

  • by

I am tring to copy the name of the image only. Trying to pull it for from below code src=”images/capchs/6.png” I want to copy “images/capchs/6.png” same is for Image2 and image3 as well. I am not good in the coding, someone pls help.
Thanks in advance.
from below code:

enter image description here

PFB my code:

 Sub SRC_Name()

Dim ie As New InternetExplorer, ws As Worksheet
Dim element As IHTMLElement
Set ws = ThisWorkbook.Worksheets("Unit Data")
With ie
    .Visible = True
    .Navigate2 "" & Sheets("Home").Range("C3").text

    While .Busy Or .readyState < 4: DoEvents: Wend

    Dim listings As Object, listing As Object, headers(), results(), r As Long, c As Long, item As Object
    headers = Array("Img1", "Img2")
    Set listings = .document.getElementsByTagName("td")
     Dim html2 As HTMLDocument

    Set html2 = New HTMLDocument
    ReDim results(1 To listings.Length, 1 To UBound(headers)   1)
    For Each listing In listings

        r = r   1
    On Error Resume Next

      html2.body.innerHTML = listing.outerHTML
        results(r, 1) = html2.querySelector(".cimg1").getAttribute("src")
        results(r, 2) = html2.querySelector(".cimg1").getAttribute("src")

         On Error GoTo 0

    ws.Cells(1, 1).Resize(1, UBound(headers)   1) = headers
    ws.Cells(2, 1).Resize(UBound(results, 1), UBound(results, 2)) = results

End With[![enter image description here][1]][1]

Leave a Reply

Your email address will not be published. Required fields are marked *