Automatically extract div labels from link

AmazingTrans

New Member
Joined
Mar 5, 2007
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hi there excel gurus!

I have this website link for example on cell A1, eg: "Part number", and would like a method to extract the part description from the website to another cell. (I'm willing to use selenium etc).
Could someone guide me how i can do this?
HOfND2.jpg
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this macro as a starting point. The site works with IE, so we can use IE automation and the built-in HTML library. Therefore, you must set references to MS Internet Explorer and MS HTML Object library, via Tools -> References in the VBA editor.
VBA Code:
Public Sub IE_Get_Data()

    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim table As HTMLTable
    Dim tCell As HTMLTableCell
            
    Set IE = New InternetExplorer
    With IE
        .navigate "https://mall.industry.siemens.com/mall/en/us/Catalog/Search?searchTerm=6ES71316BF000CA0&tab=Product"
        .Visible = True
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
    End With
    
    Do
        Set table = HTMLdoc.getElementById("ProductGrid")
        DoEvents
    Loop While table Is Nothing
    For Each tCell In table.getElementsByClassName("ProductName")
        Debug.Print tCell.Children(1).innerText
    Next

End Sub
The URL returns 2 products and the macro extracts both product descriptions.
 
Upvote 0
Try this macro as a starting point. The site works with IE, so we can use IE automation and the built-in HTML library. Therefore, you must set references to MS Internet Explorer and MS HTML Object library, via Tools -> References in the VBA editor.
VBA Code:
Public Sub IE_Get_Data()

    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim table As HTMLTable
    Dim tCell As HTMLTableCell
           
    Set IE = New InternetExplorer
    With IE
        .navigate "https://mall.industry.siemens.com/mall/en/us/Catalog/Search?searchTerm=6ES71316BF000CA0&tab=Product"
        .Visible = True
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
    End With
   
    Do
        Set table = HTMLdoc.getElementById("ProductGrid")
        DoEvents
    Loop While table Is Nothing
    For Each tCell In table.getElementsByClassName("ProductName")
        Debug.Print tCell.Children(1).innerText
    Next

End Sub
The URL returns 2 products and the macro extracts both product descriptions.
Hi John, it works great. I appreciate it!
I have another cell i would like to get, how do i get this price here given that id ?
ZDlj2t.jpg
 
Upvote 0
Maybe table.getElementById("ListPriceDiv_0").innerText. If there are multiple products I guess you would need to construct the id string in a loop ("ListPriceDiv_" & n), where n is the loop variable, starting at zero until an element with that id doesn't exist.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top