Solved

pulling info from a website and putting information into listbox

Posted on 2014-02-12
3
154 Views
Last Modified: 2014-02-14
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
Comment
Question by:fordraiders
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
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
 
LVL 3

Author Comment

by:fordraiders
Comment Utility
macroshadow, Very nicely done thanks.

Can each item i add go into a seperate column in the listbox ?
0
 
LVL 3

Author Closing Comment

by:fordraiders
Comment Utility
thanks... You answered my initial question
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now