Scrape what after STRING tag

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
Hello everyone
I am trying to get the text after each STRONG tag but I can't figure it out
Here's the code so far
Code:
Sub Final()
    Dim xmlP As New MSXML2.XMLHTTP60
    Dim htmlSubyDoc As New MSHTML.HTMLDocument
    Dim htmlSubyResults As MSHTML.IHTMLElementCollection
    Dim htmlSubyResult As MSHTML.IHTMLElement
    Dim htmlStrongs As MSHTML.IHTMLElementCollection
    Dim htmlStrong As MSHTML.IHTMLElement
    
    Dim str As String
    Dim r As Long
    Dim i As Long
    Dim counter As Long


    Application.ScreenUpdating = False




    xmlP.Open "GET", "http://plants.newgarden.com/12190005/Plant/3394/Deodar_Cedar", False
    xmlP.send


    If xmlP.Status <> 200 Then
        MsgBox "Problem" & vbNewLine & xmlP.Status & " - " & xmlP.statusText
        Exit Sub
    End If


    htmlSubyDoc.body.innerHTML = xmlP.responseText


    Set htmlSubyResults = htmlSubyDoc.getElementsByClassName("pdpBox")


    For Each htmlSubyResult In htmlSubyResults


        'Debug.Print htmlSubyResult.innerHTML
        Set htmlStrongs = htmlSubyResult.getElementsByTagName("STRONG")
        For Each htmlStrong In htmlStrongs
            Debug.Print htmlStrong.innerHTML
            
        Next htmlStrong
    Next htmlSubyResult


    Application.ScreenUpdating = True
End Sub
 
EDIT: I'm not able use Code tags due to HTML content in reptags array. Before you run this code, Remove the first and last line i.e before the subroutine and after the subroutine.
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Although there is < strong > tag, but < p > tag does not contain the text because it is in the next tag
Therefore I think you should be looking at P tags. The text next to "Height:" etc. is in the same P tag. The text below "Description:" etc. is in the next P tag(s), i.e. the nextSibling node(s).
 
Upvote 0
Resturn what after STRONG tags ...what after Height & Spread & Sunlight & Hardiness Zone & Other Names & Description & Ornamental Features & Landscape Attributes & Plant Characteristics
Are you interested in specifically those items (Height, Spread, Sunlight, Hardiness Zone, Other Names, Description, Ornamental Features, Landscape Attributes and Plant Characteristics) and nothing more? Or could there be other items that you might also want? It appears that each of the items you listed are followed by a colon... is that always the case, especially if there are other items that you want which you did not list? The reason I am asking these questions is that the STRONG tag seems to be applied against more that I think you ultimately want and this tag might have other text within the tag along with the word "strong" and the location of the ending STRONG tag is variable in location plus you want some of the text that follows it, so I am looking for other ways to narrow down the output. I think I can do it, but I need you to answer the above questions first so I know how to design the code.
 
Last edited:
Upvote 0
@Rick
Yes each item needed is followed by : (colon)
As for other replies I will give it a try to see
What about an item with a colon that has no number or text after it (before the next tag)... did you still want that returned by the function or not? Or did you only want to see items that had a value associated with it?
 
Upvote 0
What about an item with a colon that has no number or text after it (before the next tag)... did you still want that returned by the function or not? Or did you only want to see items that had a value associated with it?

I don't know exactly what you mean .. but I need all items that have a value associated to it
 
Upvote 0
I don't know exactly what you mean .. but I need all items that have a value associated to it
When I look at, for example, "Description:", there is no text after it... did you want to see "Description:" listed even though there is no actual descriptive text associated with it, just the word and a colon by itself?
 
Upvote 0
When I look at, for example, "Description:", there is no text after it... did you want to see "Description:" listed even though there is no actual descriptive text associated with it, just the word and a colon by itself?


Rick,

There is text available in Description: i.e A grand spreading tree with a broad habit of growth, pendulous branches and shimmering silvery-blue needles; best used for its majestic architectural qualities as a solitary landscape accent, needs lots and lots of space to grow for full effect

Op wants value from each and every field he mentioned on the webpage. Value is associated with every field on the link he shared.
 
Upvote 0
No matter of the string "Description" itself .. What is matter for me the sentence below it which is the description details
 
Upvote 0
No matter of the string "Description" itself .. What is matter for me the sentence below it which is the description details
Ah, I missed that the text was below it. I wish I understood the structure of this file better. The actual text description is shown with this in front of it...

< p class="CCPageText">

Do you know if that exact tag (without the space between the less than symbol and the "p" that I had to insert in order to make it visible in my message) will always appear before it?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,695
Members
449,464
Latest member
againofsoul

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