SaveText.Ru

getid
  1. Sub GetPricingFromWeb()
  2.  
  3.     Dim IE As InternetExplorer
  4.     Dim HTMLDoc As IHTMLDocument
  5.     Dim Elements As IHTMLElementCollection
  6.     Dim Element As IHTMLElement, ElementList As IHTMLElement
  7.     Dim ElementTable As IHTMLTable
  8.     Dim incrRow As Long, incrCol As Long, LoopBReak As Long
  9.     Dim URL As String, strPN As String
  10.  
  11.     strPN = "91731A049"
  12.     URL = "http://www.mcmaster.com/#" & strPN
  13.     Debug.Print "URL = " & URL
  14.  
  15.     Set IE = New InternetExplorer
  16.  
  17.     With IE
  18.         .navigate URL
  19.         .Visible = False
  20.         'Waiting till page loads
  21.         Do While .readyState <> READYSTATE_COMPLETE
  22.             DoEvents
  23.             Debug.Print "Waiting on IE" & Time
  24.         Loop
  25.  
  26.     End With
  27.  
  28.     Set HTMLDoc = IE.Document
  29.     'Wait till document load is complete
  30.     Do While HTMLDoc.readyState <> "complete"
  31.         DoEvents
  32.         Debug.Print "Waiting on document" & Time
  33.     Loop
  34.  
  35.     Do While IsNull(HTMLDoc.getElementById("Prce")): DoEvents: Loop
  36.  
  37.     If Not HTMLDoc Is Nothing Then
  38.         Set ElementList = HTMLDoc.getElementById("Prce") ' <-- error code 424, object required
  39.         Debug.Print "InnerHTML" & vbNewLine & ElementList.innerHTML
  40.     End If
  41.     If Not ElementList Is Nothing Then
  42.         Set Elements = ElementList.Children
  43.         Debug.Print "Number of elements " & Elements.Length
  44.     Else
  45.         GoTo SkipProcedure
  46.     End If
  47.  
  48.     For Each Element In Elements
  49.  
  50.         Debug.Print "Element Class name = " & Element.className
  51.         If Element.className = "PrceTierTbl" Then
  52.             Set ElementTable = Element
  53.             If Not ElementTable Is Nothing Then
  54.                 Debug.Print "ElementTableRows"
  55.                 For incrRow = 0 To ElementTable.Rows.Length - 1
  56.                     For incrCol = 0 To ElementTable.Rows(incrRow).Cells.Length - 1
  57.                         Debug.Print "InnerText @ (" & incrRow & "," & incrCol & ") = " & ElementTable.Rows(incrRow).Cells(incrCol).innerText
  58.                     Next incrCol
  59.                 Next incrRow
  60.             End If
  61.         End If
  62.     Next
  63.  
  64.     IE.Quit
  65.  
  66.     Exit Sub
  67.  
  68. SkipProcedure:
  69.         MsgBox "nothing happened"
  70.         IE.Quit
  71. End Sub

Share with your friends:

Print