Advertisement
alphaservice

VBA_Module_1

Jun 27th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Sub dataBizBuy1() 's()
  4.  
  5. Dim IE As InternetExplorer
  6. Dim listedBy As Object
  7. Dim adP As HTMLDocument
  8. Dim HTMLdoc As HTMLDocument
  9. Dim ws1 As Worksheet
  10. Dim ws2 As Worksheet
  11. Dim ws3 As Worksheet
  12. Dim intRows As Long
  13. Dim rowNo As Long
  14. Dim adID As Variant
  15. Dim askingPrice As Variant
  16. Dim brokerFirm As Variant
  17. Dim cashFlow As Variant
  18. Dim doc As Variant
  19. Dim ebitda As Variant
  20. Dim ele As Variant
  21. Dim elediv As Variant
  22. Dim element As Variant
  23. Dim employees_1 As Variant
  24. Dim established_1 As Variant
  25. Dim ffe_1 As Variant
  26. Dim grossRevenue As Variant
  27. Dim inventory_1 As Variant
  28. Dim listedBy_1 As Variant
  29. Dim location_1 As Variant
  30. Dim mtbl_1 As Variant
  31. Dim mtbl_2 As Variant
  32. Dim realEstate_1 As Variant
  33. Dim rent_1 As Variant
  34. Dim subTitle_1 As Variant
  35. Dim title_1 As Variant
  36. Dim txt As Variant
  37. Dim url As Variant
  38. Dim http As Object
  39. Dim urls() As Variant
  40. Dim html As MSHTML.HTMLDocument
  41.  
  42.  
  43. Set http = CreateObject("MSXML2.XMLHTTP")
  44. Set html = New MSHTML.HTMLDocument
  45.  
  46. Dim url2 As Long
  47. Dim results() As Variant
  48.  
  49. Set IE = New InternetExplorer
  50. IE.Visible = True
  51.  
  52. Set ws1 = ThisWorkbook.Sheets("websiteURL")
  53. Set ws2 = ThisWorkbook.Sheets("Labels")
  54. Set ws3 = ThisWorkbook.Sheets("ScrapingResults")
  55.  
  56. ws1.Range("B1").value = "=CountA(A:A)"
  57. intRows = ws1.Range("B1").value
  58.  
  59. For rowNo = 2 To intRows
  60.  
  61. url = ws1.Range("A" & rowNo).Text
  62. IE.navigate url
  63.  
  64. Do While IE.Busy Or IE.readyState <> 4
  65. Application.Wait DateAdd("s", 1, Now)
  66. Loop
  67.  
  68. Set doc = IE.document
  69.  
  70.  
  71. With doc.querySelectorAll("div.span8 > h1,h2")
  72. If .Length > 0 Then
  73. If Left(.Item(0).innerText, 36) <> "This listing is no longer available." Then
  74.  
  75. title_1 = doc.getElementsByClassName("bfsTitle")(0).innerText
  76. ws3.Range("C" & rowNo).value = title_1
  77.  
  78. subTitle_1 = doc.getElementsByClassName("span8")(0).innerText
  79. ws3.Range("D" & rowNo).value = subTitle_1
  80.  
  81. For Each ele In doc.getElementsByClassName("title")
  82. txt = ele.parentElement.innerText
  83.  
  84. If Left(txt, 12) = "Asking Price" Then
  85. askingPrice = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  86. ElseIf Left(txt, 9) = "Cash Flow" Then
  87. cashFlow = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  88. ElseIf Left(txt, 13) = "Gross Revenue" Then
  89. grossRevenue = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  90. ElseIf Left(txt, 6) = "EBITDA" Then
  91. ebitda = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  92. ElseIf Left(txt, 4) = "FF&E" Then
  93. ffe_1 = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  94. ElseIf Left(txt, 9) = "Inventory" Then
  95. inventory_1 = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  96. ElseIf Left(txt, 11) = "Real Estate" Then
  97. realEstate_1 = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  98. ElseIf Left(txt, 4) = "Rent" Then
  99. rent_1 = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  100. ElseIf Left(txt, 11) = "Established" Then
  101. established_1 = Trim(Mid(txt, InStrRev(txt, ":") + 1))
  102. End If
  103. Next ele
  104.  
  105. ws3.Range("E" & rowNo).value = askingPrice
  106. ws3.Range("F" & rowNo).value = cashFlow
  107. ws3.Range("G" & rowNo).value = grossRevenue
  108. ws3.Range("H" & rowNo).value = ebitda
  109. ws3.Range("I" & rowNo).value = ffe_1
  110. ws3.Range("J" & rowNo).value = inventory_1
  111. ws3.Range("K" & rowNo).value = realEstate_1
  112. ws3.Range("L" & rowNo).value = rent_1
  113. ws3.Range("M" & rowNo).value = established_1
  114.  
  115. Set mtbl_1 = doc.getElementsByClassName("broker")(0)
  116. Set listedBy = mtbl_1.getElementsByTagName("a")(1)
  117. listedBy_1 = listedBy.innerText
  118. ws3.Range("N" & rowNo).value = listedBy_1
  119.  
  120. brokerFirm = doc.querySelector("div.broker > h4").innerText
  121. ws3.Range("O" & rowNo).value = brokerFirm
  122.  
  123. Set mtbl_2 = doc.getElementsByClassName("disclaimer")(0)
  124. Set adP = mtbl_2.getElementsByTagName("p")(0)
  125. ws3.Range("P" & rowNo).value = Split(adP.innerText, ":")(1)
  126.  
  127.  
  128. End If
  129.  
  130. If ws3.Range("C" & rowNo).value = "" Then
  131. ws3.Range("B" & rowNo).value = "Not available"
  132. End If
  133.  
  134. End If
  135. End With
  136.  
  137. Next
  138.  
  139. IE.Quit
  140. Set IE = Nothing
  141. MsgBox "done"
  142.  
  143. End Sub
  144.  
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement