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
Solved

pulling info from a website and putting information into listbox

Posted on 2014-02-12
3
160 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 27

Accepted Solution

by:
MacroShadow earned 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

840 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