[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

pulling info from a website and putting information into listbox

Posted on 2014-02-12
3
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 2000 total points
ID: 39858409
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
ID: 39859241
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
ID: 39860088
thanks... You answered my initial question
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

656 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