Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function PriceGrabId(url As String, htmlID As String, CellRow As Integer, CellColumn As Integer, CellName As String)
- Dim doc As Object
- Dim x As Long
- Dim price As String
- Dim oElement As Object
- 'Get HTML File
- Set doc = CreateObject("htmlfile")
- With CreateObject("MSXML2.XMLHTTP")
- .Open "GET", url
- .send
- Do: DoEvents: Loop Until .readystate = 4
- doc.body.innerHTML = .responsetext
- .abort
- End With
- 'Get the text from element id
- price = doc.getElementById(htmlID).InnerText
- Sheet1.Cells(CellRow, CellColumn).Value = price
- Range(CellName).NumberFormat = "General"
- End Function
- Public Function PriceGrabTag(url As String, htmlTag As String, htmlIndex As Integer, CellRow As Integer, CellColumn As Integer, CellName As String)
- Dim doc As Object
- Dim x As Long
- Dim price As String
- Dim oElement As Object
- Set doc = CreateObject("htmlfile")
- With CreateObject("MSXML2.XMLHTTP")
- .Open "GET", url
- .send
- Do: DoEvents: Loop Until .readystate = 4
- doc.body.innerHTML = .responsetext
- .abort
- End With
- 'read all elemens with same tag, html index is the index of the item i want
- price = doc.getElementsByTagName(htmlTag).Item(htmlIndex).InnerText
- Sheet1.Cells(CellRow, CellColumn).Value = price
- Range(CellName).NumberFormat = "General"
- End Function
- Public Function PriceGrabPrice(url As String, htmlTag As String, htmlIndex As Integer, CellRow As Integer, CellColumn As Integer, CellName As String)
- Dim doc As Object
- Dim x As Long
- Dim usd As String
- Dim oElement As Object
- Set doc = CreateObject("htmlfile")
- With CreateObject("MSXML2.XMLHTTP")
- .Open "GET", url
- .send
- Do: DoEvents: Loop Until .readystate = 4
- doc.body.innerHTML = .responsetext
- .abort
- End With
- usd = doc.getElementsByTagName(htmlTag).Item(htmlIndex).InnerText
- Sheet1.Cells(CellRow, CellColumn).Value = Left(usd, 8)
- Range(CellName).NumberFormat = "General"
- End Function
- Public Sub Scrape()
- Call PriceGrabPrice("http://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=EUR", "td", 2, 2, 6, "F2")
- 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")
- Call PriceGrabId("http://www.b2cbuying.com/huawei-honor-6-smartphone.html", "product-price-280", 3, 2, "B3")
- 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")
- Call PriceGrabId("http://www.oppomart.com/honor6/huawei-honor-6.html", "product-price-548", 6, 2, "B6")
- Call PriceGrabTag("http://www.merimobiles.com/huawei-honor-5-inch-lte-octa-core-3gb-16gb-smartphone_p/meri10357.htm", "em", 14, 5, 2, "B5")
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment