[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

pulling info from a website and putting information into listbox

excel vba

Userform1
Listbox
Commandbutton

webbrowser1 object on userform


What I need:
After I navigate to a website:
The web page displays several items on the web page.

I need to find every instance of the html code below and put certain intomation into a listbox:

That starts with this html code part:
</a></div><div class

</a></div><div class="productDescription"><p class="productName"><a href="/product/VAUGHAN-Curved-Claw-Hammer-6CLR0?s_pp=false&sgAttributes=" class="productLink" title="Curved-Claw Hammer, Steel, 20 Oz, Smooth">Curved-Claw Hammer, Steel, 20 Oz, Smooth</a></p><p class="productBrand"> VAUGHAN</p><p class="productInfo" id="itemNumber2">Grainger Item # <a href="/product/VAUGHAN-Curved-Claw-Hammer-6CLR0?s_pp=false&sgAttributes=" class="productLink" title="Curved-Claw Hammer, Steel, 20 Oz, Smooth"><span class="productInfoValueList"> 6CLR0</span></a><span class="productMFR"> | Mfr. Model # <span class="productInfoValueList"> R20</span></span></p><p id="productCatalogPage2" class="productCatalog"> Catalog Page # <a href="javascript:void(0)" onclick="detectForCatalog('1117')"><span class="productInfoValueList">1117</span></a> (PDF) </p><p class="productIcons">





So from this information in the html the information i need are:
?s_pp=false&sgAttributes=" class="productLink" title="Curved-Claw Hammer, Steel, 20 Oz, Smooth"

I need:
Curved-Claw Hammer, Steel, 20 Oz, Smooth



><span class="productInfoValueList"> 6CLR0
I need :
6CLR0


</a></p><p class="productBrand"> VAUGHAN
I need:
VAUGHN


Mfr. Model # <span class="productInfoValueList"> R20
I NEED:
R20



Thanks
fordraiders
0
Fordraiders
Asked:
Fordraiders
  • 2
1 Solution
 
MacroShadowCommented:
You have to find unique text that will always be before and after the items you are interested in. Then you can use this function to extract them.

Function ExtractString(strInput As String, strUniqueStart As String, strUniqueEnd As String) As String

    ExtractString = Split(Split(strInput, strUniqueStart)(1), strUniqueEnd)(0)

End Function

Open in new window


For example
Sub Demo()

    Dim strHtml As String
    Dim strUniqueStart As String
    Dim strUniqueEnd As String

    strHtml = "</a></div><div class=""productDescription""><p class=""productName""><a href=""/product/VAUGHAN-Curved-Claw-Hammer-6CLR0?s_pp=false&sgAttributes="" class=""productLink"" title=""Curved-Claw Hammer, Steel, 20 Oz, Smooth"">Curved-Claw Hammer, Steel, 20 Oz, Smooth</a></p><p class=""productBrand""> VAUGHAN</p><p class=""productInfo"" id=""itemNumber2"">Grainger Item # <a href=""/product/VAUGHAN-Curved-Claw-Hammer-6CLR0?s_pp=false&sgAttributes="" class=""productLink"" title=""Curved-Claw Hammer, Steel, 20 Oz, Smooth""><span class=""productInfoValueList""> 6CLR0</span></a><span class=""productMFR""> | Mfr. Model # <span class=""productInfoValueList""> R20</span></span></p><p id=""productCatalogPage2"" class=""productCatalog""> Catalog Page # <a href=""javascript:void(0)"" onclick=""detectForCatalog('1117')""><span class=""productInfoValueList"">1117</span></a> (PDF) </p><p class=""productIcons"">"

    ' Extract data and show messagebox (this is only for demonstration purpose, in real life you don't need it)
    strUniqueStart = "?s_pp=false&sgAttributes="" class=""productLink"" title="""
    strUniqueEnd = "</a></p><p class=""productBrand"">"
    MsgBox Split(ExtractString(strHtml, strUniqueStart, strUniqueEnd), """>")(0)

    strUniqueStart = "<span class=""productInfoValueList"">"
    strUniqueEnd = "</span></a>"
    MsgBox ExtractString(strHtml, strUniqueStart, strUniqueEnd)

    strUniqueStart = "<p class=""productBrand"">"
    strUniqueEnd = "</p><p class=""productInfo"
    MsgBox ExtractString(strHtml, strUniqueStart, strUniqueEnd)

    strUniqueStart = "Mfr. Model # <span class=""productInfoValueList"">"
    strUniqueEnd = "</span></span></p>"
    MsgBox ExtractString(strHtml, strUniqueStart, strUniqueEnd)

    ' Add items to listbox
    With ListBox1    ' the name of your listbox
        strUniqueStart = "?s_pp=false&sgAttributes="" class=""productLink"" title="""
        strUniqueEnd = "</a></p><p class=""productBrand"">"
        .AddItem Split(ExtractString(strHtml, strUniqueStart, strUniqueEnd), """>")(0)
        strUniqueStart = "<span class=""productInfoValueList"">"
        strUniqueEnd = "</span></a>"
        .AddItem ExtractString(strHtml, strUniqueStart, strUniqueEnd)
        strUniqueStart = "<p class=""productBrand"">"
        strUniqueEnd = "</p><p class=""productInfo"
        .AddItem ExtractString(strHtml, strUniqueStart, strUniqueEnd)
        strUniqueStart = "Mfr. Model # <span class=""productInfoValueList"">"
        strUniqueEnd = "</span></span></p>"
        .AddItem ExtractString(strHtml, strUniqueStart, strUniqueEnd)
    End With

End Sub

Open in new window

0
 
FordraidersAuthor Commented:
macroshadow, Very nicely done thanks.

Can each item i add go into a seperate column in the listbox ?
0
 
FordraidersAuthor Commented:
thanks... You answered my initial question
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now