• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to find another tag in a class name of IE by vba excel

Hi Team

I have attached a file in which you can see three images.

First image showing three laptops and one missing laptop showing only white.

Next two images showing the code behind the images.

First image of code showing the trend code showing how the images have been given place on page

and another code has no image source code. this second code doesnt have the image related to missing laptop.

So I am making a web crawler for the same. How can I check that the image is missing from page or not?

Please help this is very crucial.

Thanks
RatanB
 

Attachments

  • Code.docx
    320.8 KB · Views: 8
Hi

Marc

Yes there is no img tag but when I am extracting the information in excel file, the img tag is extracting the src code for that particular code...

SOo how can I check this

Please help

Thanks
RatanB
 
I very do not understand how can you extract a non existing tag ?!

So it depends on the Excel purpose which I have no idea (!)
and on your code you forgot to post here (using code icon)
or just attach your workbook …
 
Code:
Sub test()
    Set ie = New InternetExplorerMedium
    ie.Visible = True
    ie.navigate "http://ost.dell.com/OST/UI/AdvanceAccountSearch.aspx"
    Call Busy
   
    Set doc = ie.document
   
    doc.getElementById("ctl00_topHeaderControl_tbContrHeader_tbpnlPgSetting_lbtnAdvSearch").Click
    Call Busy
   
    doc.getElementById("ctl00_ContentPageHolder_txtRCNo").Value = ThisWorkbook.Worksheets("Image Missing, Broken, Incorrec").Range("M188").Value
   
    doc.getElementById("ctl00_ContentPageHolder_lnkbtnSearch").Click
    Call Busy
   
    doc.getElementById("ctl00_ContentPageHolder_gvAccounts_ctl02_lnkbtnPreview").Click
   
    doc.getElementById("ctl00_ContentPageHolder_ddlGridRolesPrvw").selectedIndex = 2
   
    doc.getElementById("ctl00_ContentPageHolder_imgbtnGridPgPrevw").Click
    Call Busy
   
    With CreateObject("Shell.Application").Windows
        Set ie = .Item(.Count - 1)
    End With
   
    Set doc = ie.document
   
    doc.getElementsByClassName("mNav").Item(0).Click
   
    Set Data = ie.document.getElementsByTagName("strong")
    j = 1
        For Each x In Data
        ThisWorkbook.Worksheets("Sheet1").Range("A" & j).Value = x.innerText
        x.Click
      a = 33
    Set doc = ie.document


MsgBox doc.getElementsByClassName("hv_cluetip")(3).getElementsByTagName("img")(0).getAttribute("src")


End Sub
 
This is the above code I am using to extract every image name in a loop, so this should miss the image name which is not in code image yet is giving the name, title, src and all...
 

As I can't reach the URL …

So set an object variable on .getElementsByTagName("IMG")
and check its Length : if zero there is no image …
 
Marc, you wont be able to reach webpage because its work internally.

But I have tried your ways, and I am getting length 1 for all. There is no 0 for IMG tag anywhere in whole page.
 

What a weird webpage !
Or maybe it's your code, as I never had 1 for a non existing tag, show me …

Other way for beginner is to check within innerHTML code of an "A" tag
if "<img" exists …
 
Code:
With IE.Document.getElementsByClassName("hv_cluetip")
    For N& = 0 To .Length - 1
        With .Item(N).getElementsByTagName("IMG")
            For S& = 0 To .Length - 1
                Debug.Print "hv_cluetip #"; N, " src = "; .Item(S).getAttribute("src")
            Next
            If .Length = 0 Then Debug.Print "hv_cluetip #"; N; " :  no image !"
        End With
    Next
End With
See result in VBE Immediate window (Ctrl + G) …
 
what I have observed in src code, where there is an image, src contains ".jpg" in the end and where there is no image, it doesnot have ".jpg". what do you think marc...
 

So it seems all href elements have an img element
but as you can see within the result the third element (# 2)
and other do not have a ".jpg" extension at end of their src attribute …

Edit : I think you got it !
 
Code:
With IE.Document.getElementsByClassName("hv_cluetip")
    For N& = 0 To .Length - 1
        With .Item(N).getElementsByTagName("IMG")
            If .Length Then
                T$ = .Item(0).getAttribute("src")
                T$ = IIf(T Like "*.jpg", "  image : " & T, "no image")
                Debug.Print "hv_cluetip #" & N; Tab(20); T
            End If
        End With
    Next
End With
Or T$ = IIf(T Like "*/images/*",
 
Back
Top