Guest User

Untitled

a guest
Jul 31st, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Function PriceGrabId(url As String, htmlID As String, CellRow As Integer, CellColumn As Integer, CellName As String)
  2.  
  3. Dim doc As Object
  4. Dim x As Long
  5. Dim price As String
  6. Dim oElement As Object
  7. 'Get HTML File
  8. Set doc = CreateObject("htmlfile")
  9. With CreateObject("MSXML2.XMLHTTP")
  10.     .Open "GET", url
  11.     .send
  12.     Do: DoEvents: Loop Until .readystate = 4
  13.     doc.body.innerHTML = .responsetext
  14.     .abort
  15. End With
  16.  
  17. 'Get the text from element id
  18. price = doc.getElementById(htmlID).InnerText
  19.    
  20.             Sheet1.Cells(CellRow, CellColumn).Value = price
  21.             Range(CellName).NumberFormat = "General"
  22.        
  23. End Function
  24.  
  25. Public Function PriceGrabTag(url As String, htmlTag As String, htmlIndex As Integer, CellRow As Integer, CellColumn As Integer, CellName As String)
  26.  
  27. Dim doc As Object
  28. Dim x As Long
  29. Dim price As String
  30. Dim oElement As Object
  31.  
  32. Set doc = CreateObject("htmlfile")
  33.  
  34. With CreateObject("MSXML2.XMLHTTP")
  35.     .Open "GET", url
  36.     .send
  37.     Do: DoEvents: Loop Until .readystate = 4
  38.     doc.body.innerHTML = .responsetext
  39.     .abort
  40. End With
  41. 'read all elemens with same tag, html index is the index of the item i want
  42. price = doc.getElementsByTagName(htmlTag).Item(htmlIndex).InnerText
  43.      
  44.             Sheet1.Cells(CellRow, CellColumn).Value = price
  45.            
  46. Range(CellName).NumberFormat = "General"
  47. End Function
  48. Public Function PriceGrabPrice(url As String, htmlTag As String, htmlIndex As Integer, CellRow As Integer, CellColumn As Integer, CellName As String)
  49.  
  50. Dim doc As Object
  51. Dim x As Long
  52. Dim usd As String
  53. Dim oElement As Object
  54.  
  55. Set doc = CreateObject("htmlfile")
  56.  
  57. With CreateObject("MSXML2.XMLHTTP")
  58.     .Open "GET", url
  59.     .send
  60.     Do: DoEvents: Loop Until .readystate = 4
  61.     doc.body.innerHTML = .responsetext
  62.     .abort
  63. End With
  64.  
  65. usd = doc.getElementsByTagName(htmlTag).Item(htmlIndex).InnerText
  66.      
  67.             Sheet1.Cells(CellRow, CellColumn).Value = Left(usd, 8)
  68.            
  69. Range(CellName).NumberFormat = "General"
  70. End Function
  71.  
  72. Public Sub Scrape()
  73.  
  74. Call PriceGrabPrice("http://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=EUR", "td", 2, 2, 6, "F2")
  75. Call PriceGrabId("http://www.minideal.net/huawei-honor-6-4g-lte-smartphone-android-4-4-octa-core-3gb-16gb-5-inch-13mp-camera.html", "product-price-1633_clone", 2, 2, "B2")
  76. Call PriceGrabId("http://www.b2cbuying.com/huawei-honor-6-smartphone.html", "product-price-280", 3, 2, "B3")
  77. Call PriceGrabId("http://www.1949deal.com/huawei-honor-6-kirin-920-octa-core-1-7ghz-android-4-4-smartphone-3gb-ram-16gb-rom-5-0-inch-fhd-gorilla-glass-screen-4g-lte-black.html", "product-price-1975", 4, 2, "B4")
  78. Call PriceGrabId("http://www.oppomart.com/honor6/huawei-honor-6.html", "product-price-548", 6, 2, "B6")
  79. Call PriceGrabTag("http://www.merimobiles.com/huawei-honor-5-inch-lte-octa-core-3gb-16gb-smartphone_p/meri10357.htm", "em", 14, 5, 2, "B5")
  80.  
  81. End Sub
Advertisement
Add Comment
Please, Sign In to add comment