Scraping the HTML of a new tab opened with .click

DHSOLBIZ

New Member
Joined
Jul 26, 2016
Messages
5
I am having trouble getting my Sub to pull in the HTML of a new tab opened using .click within the routine. It pulls open the first instance of IE, just fine. It then searches the links on that page for a particular string, and clicks the link, when the string is found. Next, I need it to search the HTML of the new tab for a div with a particular class name, and pull the text from the div. The HTML pulled with .innerHTML appears incomplete. Furthermore, I examine the HTML in a MsgBox for the first page, and, what I expect to be the second tab, and the results are the same. The code is here
Code:
Private Sub PrcButton_Click()    'Define IE as an Visible Internet Explorer Window, Item as a string (part number) to be searched on website
            
    Dim IE As New InternetExplorer
    IE.Visible = True
    Dim Price As String
    'Price = ""
    'Dim A As Range: Set A = Sheets("Sheet1").Range("A3:A2000")
    Dim Item As String
    'For Each Item In A:
    
    'Set Item as a particular part number, Navigate to the Search Results on the page for Item
       
    Item = "1300RE-24"
    
    
    
    IE.navigate "http://www.wholesalesolar.com/search?cx=016891376637286370789%3A57yxrli0cuq&cof=FORID%3A11%3BNB%3A1&ie=UTF-8&q=" & Item & "&sa=Search"
    
    'Loop until the page is loaded
    Do
        DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE
    
    'Search links on page for exact part number and click the link with the exact match
       
    Set Links = IE.document
    For Each link In Links.Links
        If InStr(link.innerText, Item) > 0 Then
           link.Click


            Exit For
        End If
                
    
    Next
    
    'Loop until the page is loaded
    Do While IE.readyState <> READYSTATE_COMPLETE
    
    Do
        DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE
    
    Loop
    
    'Add time for page to load
    
    'T1 = Now
    'Do While (Now < T1 + TimeValue("0:00:40"))
    'DoEvents
    'Loop
    


    'Reset Links to the new page-----------THIS IS WHERE I AM HAVING TROUBLE------------
    Set Links = IE.document
        
    'FOR EXAMINING NEW PAGE HTML
    'Links_HTML = Links.body.innerHTML
    
    'Search HTML from new page for price
    For Each item_blck In Links.getElementsByClassName("product-row")
        item_HTML = item_blck.document.innerHTML
        item_price = item_HTML.getElementsByClassName("price")(0).innerText
        
        
    Next
    
    'Show what you find
    MsgBox item_HTML
    
    '-------ALWAYS SHOWS BLANK. I THINK IT IS LOOKING AT HTML FROM ORIGINAL PAGE---------
    
    'item_test = item_HTML.innerHTML
     
        
    'If InStr(Page_HTML, "cart") > 0 Then
    'Page_HTML = Mid(Page_HTML, InStr(Page_HTML, "price"), Len(Page_HTML))
    'Dim item_price As String
    
    'item_price = Mid(Page_HTML, 1, InStr(Page_HTML, "</div>=="))
    
    'Price = CDbl(item_price)
    
        
    'End If
    
    'Sheets(Sheet1).Range(F4).Value = item_price
    
    


 
    
    
       
    
    'Next Item
      


    
    
End Sub

There are a lot of lines commented out, but also actual comments describing what the code should do. Any assistance is Greatly Appreciated.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Was it necessary to use InternetExplorer object? Couldn't you use WinHttpRequest or XmlHTTP60? InternetExplorer has lots of quirks.
 
Upvote 0
Was it necessary to use InternetExplorer object? Couldn't you use WinHttpRequest or XmlHTTP60? InternetExplorer has lots of quirks.

Honestly, I don't know. I am brand new to VBA, and am just going off of tutorials and videos I have found online. I am open to suggestions on the most efficient way to get the job done, Details will be extremely helpful.
 
Upvote 0
To get the job done, you have to fully describe what do you need. Go there, take that thing and put it there etc. :)
 
Upvote 0
To get the job done, you have to fully describe what do you need. Go there, take that thing and put it there etc. :)
Thanks for the detail. It doesn't seem to be opening the HTML the same as I could in Chrome. You are right about quirky. When I examine source in IE, it has all of the information and divs I am looking for separated as text in a ********>. Can you give me any tips on using XNLHTTP, or some other method?
 
Upvote 0
The general algorithm is the following:
Code:
Sub F()
    Dim req As Object
    Dim html As String
    Set req = CreateObject("WinHttp.WinHttpRequest")
    req.Open "GET", "YOUR_URL", False
    req.Send
    If req.Status = 200 Then
        html = req.ResponseText
    End If
End Sub
 
Upvote 0
What if I don't know the second URL? The first part searches a website for an item number. it then searches the links brought up for the exact item number and clicks the link to that item's page. The price information is on this second page. I need to do this for a couple thousand items, on 15 different sites.
 
Upvote 0
I keep getting Run-time error '429': ActiveX component can't create object. The only thing I've found on this relates to OSX, but I am on a Windows10 machine.
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,601
Members
449,109
Latest member
Sebas8956

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