Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.01 KB | None | 0 0
  1.  
  2. Option Explicit
  3.  
  4. Sub 최저가현황()
  5.  
  6. Application.ScreenUpdating = False
  7.  
  8. Application.Calculation = xlCalculationManual
  9.  
  10. Application.EnableEvents = False
  11.  
  12. Application.DisplayStatusBar = False
  13.  
  14. ActiveSheet.DisplayPageBreaks = False
  15.  
  16.  
  17. Dim Naver As String, Aurl As String, Gurl As String, Iurl As String, STurl As String
  18. Naver = "https://search.shopping.naver.com/detail/price_compare_area.nhn?" & "nvMid=" & ActiveCell.Offset(-2, 32).Value & "&pkey=" & ActiveCell.Offset(-2, 33).Value
  19. Aurl = "http://itempage3.auction.co.kr/DetailView.aspx?itemno="
  20. Gurl = "http://item.gmarket.co.kr/Item?goodscode="
  21. Iurl = "http://shopping.interpark.com/product/productInfo.do?viewTp=preview&prdNo="
  22. STurl = "http://www.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo="
  23.  
  24. On Error Resume Next
  25.  
  26. Dim i As Integer, ed As Integer
  27.  
  28. Dim ABLEcode(3) As String
  29.  
  30. ABLEcode(0) = ActiveCell.Offset(-2, -1).Value
  31. ABLEcode(1) = ActiveCell.Offset(-2, 4).Value
  32. ABLEcode(2) = ActiveCell.Offset(-1, 4).Value
  33. ABLEcode(3) = ActiveCell.Offset(0, 4).Value
  34.  
  35. Dim htmlA(2) As String, htmlG(2) As String, htmlI(2) As String, html11(2) As String, beginA(2) As Double, beginG(2) As Double, endA(2) As Double, endG(2) As Double, beginI(2) As Double, endI(2) As Double, begin11(3) As Double, end11(3) As Double
  36. Dim result(20) As String
  37. Dim temp As Object, temp2 As Object, Code(20) As String, Title(20) As String, Price(20) As String, Mall(20) As String, PPrice(20) As String, Seller(20) As String, sale(20) As String, Link(20) As String, linktemp As String
  38. Erase Link
  39.  
  40. Dim winhttp As New WinHttpRequest
  41. Dim HTML1 As MSHTML.HTMLDocument
  42. Dim elemCol As MSHTML.IHTMLElement
  43. Set HTML1 = New MSHTML.HTMLDocument
  44.  
  45. With winhttp
  46. .Open "POST", Naver
  47. .SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0"
  48. .SetRequestHeader "Referer", "https://search.shopping.naver.com/detail/detail.nhn?"
  49. .Send
  50. HTML1.body.innerHTML = .ResponseText
  51. End With
  52.  
  53. ed = 20
  54.  
  55. For i = 1 To ed
  56. Set elemCol = HTML1.getElementsByClassName("tbl tbl_v")(i)
  57. Set temp = elemCol.tBodies(0)
  58. Code(i) = temp.Children(0).getAttribute("data-mall-pid")
  59.  
  60. Link(i) = temp.getElementsByTagName("A")
  61.  
  62. Set temp2 = temp.getElementsByTagName("img")
  63. Mall(i) = temp2.Item(0).alt
  64.  
  65.  
  66. Set temp = HTML1.getElementsByClassName("lft")
  67. Set temp2 = temp(i - 1).getElementsByTagName("a")
  68. Title(i) = temp2(0).innerText
  69.  
  70. Set temp = HTML1.getElementsByClassName("td_price")
  71. Price(i) = Split(temp(i - 1).innerText, "원")(0)
  72. If InStr(1, Price(i), "최저") > 0 Then
  73. Price(i) = Split(Price(i), "최저")(1)
  74. End If
  75.  
  76. If Price(i) = "" Then
  77. Title(i) = ""
  78. Seller(i) = ""
  79. sale(i) = ""
  80. PPrice(i) = ""
  81. Link(i) = ""
  82. ed = i - 1
  83. Exit For
  84. End If
  85. Next i
  86.  
  87. For i = 1 To ed
  88.  
  89. Select Case Mall(i)
  90.  
  91. Case "옥션"
  92.  
  93. htmlA(1) = getHTML("http://itempage3.auction.co.kr/DetailView.aspx?itemNo=" & Code(i))
  94.  
  95. beginA(1) = InStr(1, htmlA(1), "price_original") '정산 파트
  96.  
  97. If beginA(1) = 0 Then
  98. beginA(1) = InStr(1, htmlA(1), "price_real")
  99. End If
  100.  
  101. If beginA(1) = 0 Then
  102. result(i) = "0"
  103. End If
  104.  
  105. endA(1) = InStr(beginA(1), htmlA(1), "<")
  106.  
  107. If beginA(1) = InStr(1, htmlA(1), "price_original") Then
  108. result(i) = Mid(htmlA(1), beginA(1) + 16, endA(1) - beginA(1) - 16)
  109. sale(i) = (1 - (Price(i) / result(i))) * 100
  110. PPrice(i) = Application.WorksheetFunction.RoundDown(result(i) * (1 - ((9 + (sale(i) * 0.1)) / 100)), -1)
  111.  
  112. ElseIf beginA(1) = InStr(1, htmlA(1), "price_real") Then
  113. result(i) = Mid(htmlA(1), beginA(1) + 12, endA(1) - beginA(1) - 12)
  114. sale(i) = (1 - (Price(i) / result(i))) * 100
  115. PPrice(i) = Application.WorksheetFunction.RoundDown(result(i) * (1 - ((9 + (sale(i) * 0.1)) / 100)), -1)
  116. End If
  117.  
  118. beginA(2) = InStr(1, htmlA(1), "shop-title") '판매처명 파트
  119. endA(2) = InStr(beginA(2), htmlA(1), "</")
  120. Seller(i) = Mid(htmlA(1), beginA(2) + 12, endA(2) - beginA(2) - 12)
  121.  
  122. Case "G마켓"
  123.  
  124. htmlG(1) = getHTML("http://item.gmarket.co.kr/Item?goodscode=" & Code(i))
  125.  
  126. beginG(1) = InStr(1, htmlG(1), "price_original")
  127.  
  128. If beginG(1) = 0 Then
  129. beginG(1) = InStr(1, htmlG(1), "price_real")
  130. End If
  131.  
  132. If beginG(1) = 0 Then
  133. result(i) = "0"
  134. End If
  135.  
  136. endG(1) = InStr(beginG(1), htmlG(1), "<")
  137.  
  138. If beginG(1) = InStr(1, htmlG(1), "price_original") Then
  139. result(i) = Mid(htmlG(1), beginG(1) + 16, endG(1) - beginG(1) - 16)
  140. sale(i) = (1 - (Price(i) / result(i))) * 100
  141. PPrice(i) = Application.WorksheetFunction.RoundDown(result(i) * (1 - ((9 + (sale(i) * 0.1)) / 100)), -1)
  142.  
  143. ElseIf beginG(1) = InStr(1, htmlG(1), "price_real") Then
  144. result(i) = Mid(htmlG(1), beginG(1) + 12, endG(1) - beginG(1) - 12)
  145. sale(i) = (1 - (Price(i) / result(i))) * 100
  146. PPrice(i) = Application.WorksheetFunction.RoundDown(result(i) * (1 - ((9 + (sale(i) * 0.1)) / 100)), -1)
  147. End If
  148.  
  149. beginG(2) = InStr(1, htmlG(1), "shoptit") '판매처명 파트
  150. endG(2) = InStr(beginG(2) + 1, htmlG(1), "/strong>")
  151. htmlG(2) = Mid(htmlG(1), beginG(2) + 1, endG(2) - beginG(2) + 1)
  152. beginG(2) = InStr(1, htmlG(2), "<strong>")
  153. endG(2) = InStr(beginG(2) + 1, htmlG(2), "<")
  154. Seller(i) = Mid(htmlG(2), beginG(2) + 8, endG(2) - beginG(2) - 8)
  155.  
  156. Case "인터파크"
  157.  
  158. htmlI(1) = getHTML("http://shopping.interpark.com/product/productInfo.do?viewTp=preview&prdNo=" & Code(i))
  159.  
  160. beginI(1) = InStr(1, htmlI(1), "sale_price")
  161.  
  162. If beginI(1) = 0 Then
  163. result(i) = "0"
  164. End If
  165.  
  166. endI(1) = InStr(beginI(1), htmlI(1), ",")
  167.  
  168. result(i) = Mid(htmlI(1), beginI(1) + 14, endI(1) - beginI(1) - 15)
  169. sale(i) = (1 - (Price(i) / result(i))) * 100
  170.  
  171. PPrice(i) = Application.WorksheetFunction.RoundDown(result(i) * (1 - ((11 + (sale(i) * 0.1)) / 100)), -1)
  172.  
  173. beginI(2) = InStr(1, htmlI(1), "sellerNm") '판매처명 파트
  174. endI(2) = InStr(beginI(2), htmlI(1), ",")
  175. Seller(i) = Mid(htmlI(1), beginI(2) + 11, endI(2) - beginI(2) - 12)
  176.  
  177. Case "11번가"
  178.  
  179. html11(1) = getHTML("http://www.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo=" & Code(i))
  180.  
  181. begin11(1) = InStr(1, html11(1), "정상가")
  182. end11(1) = InStr(begin11(1), html11(1), "원")
  183.  
  184. If begin11(1) = 0 Then
  185. result(i) = "0"
  186.  
  187. End If
  188.  
  189. html11(2) = Mid(html11(1), begin11(1), end11(1) - begin11(1))
  190.  
  191. If InStr(1, html11(2), "strong") > 0 Then
  192. begin11(1) = InStr(1, html11(2), "sale_price")
  193. end11(1) = InStr(begin11(1), html11(2), "</strong>")
  194. result(i) = Mid(html11(2), begin11(1) + 12, end11(1) - begin11(1) - 12)
  195. sale(i) = (1 - (Price(i) / result(i))) * 100
  196. PPrice(i) = Application.WorksheetFunction.RoundDown(result(i) * (1 - ((9 + (sale(i) * 0.1)) / 100)), -1)
  197.  
  198. ElseIf InStr(1, html11(2), "normal_price") > 0 Then
  199. begin11(1) = InStr(1, html11(2), "normal_price")
  200. end11(1) = InStr(begin11(1), html11(2), "</s>")
  201. result(i) = Mid(html11(2), begin11(1) + 17, end11(1) - begin11(1) - 17)
  202. sale(i) = (1 - (Price(i) / result(i))) * 100
  203. PPrice(i) = Application.WorksheetFunction.RoundDown(result(i) * (1 - ((9 + (sale(i) * 0.1)) / 100)), -1)
  204.  
  205. End If
  206.  
  207. begin11(2) = InStr(1, html11(1), "seller_nickname") '판매처명 파트
  208. end11(2) = InStr(begin11(2), html11(1), "</a>")
  209. html11(0) = Mid(html11(1), begin11(2), end11(2) - begin11(2))
  210. begin11(3) = InStr(1, html11(0), ">")
  211. Seller(i) = Mid(html11(0), begin11(3) + 1)
  212.  
  213. Case Else
  214.  
  215. result(i) = "X"
  216. Seller(i) = "X"
  217. sale(i) = "X"
  218. PPrice(i) = "정산식 필요"
  219.  
  220. End Select
  221.  
  222. Next i
  223.  
  224. For i = 1 To 20
  225.  
  226. With Worksheets("네이버 현황")
  227. .Cells(1, 1).Value = ABLEcode(0)
  228.  
  229. If Mall(i) = "" And Seller(i) = "X" Then
  230. .Cells(i + 2, 2).Value = "X"
  231.  
  232. Else
  233. .Cells(i + 2, 2).Value = Mall(i)
  234.  
  235. End If
  236.  
  237. .Cells(i + 2, 3).Value = Title(i)
  238.  
  239. If Seller(i) = "X" Then
  240. .Cells(i + 2, 4).Value = "X"
  241.  
  242. Else
  243. .Cells(i + 2, 4).Value = Seller(i)
  244.  
  245. End If
  246.  
  247. .Cells(i + 2, 5).Value = Price(i)
  248. .Cells(i + 2, 6).Value = sale(i)
  249. .Cells(i + 2, 7).Value = PPrice(i)
  250. .Cells(i + 2, 8).Value = ""
  251. Link(i) = Split(Link(i), "http://cr2.shopping.naver.com/adcrNoti.nhn?x=")(1)
  252. Link(i) = Split(Link(i), "&nv_mid")(0)
  253. .Hyperlinks.Add Anchor:=.Cells(i + 2, 8), Address:="http://cr2.shopping.naver.com/adcrNoti.nhn?x=" & _
  254. Link(i), TextToDisplay:="☞"
  255. .Cells(i + 2, 9).Value = result(i)
  256.  
  257. .Range("H" & i + 2).HorizontalAlignment = xlCenter
  258. .Range("H" & i + 2).Interior.COLOR = RGB(255, 255, 204)
  259.  
  260. End With
  261.  
  262. Next i
  263.  
  264. With Worksheets("네이버 현황")
  265. .Cells(28, 7) = ABLEcode(1)
  266. .Cells(29, 7) = ABLEcode(2)
  267. .Cells(30, 7) = ABLEcode(3)
  268. End With
  269.  
  270.  
  271. Sheets("네이버 현황").Select
  272.  
  273.  
  274. Application.ScreenUpdating = True
  275.  
  276. Application.Calculation = xlCalculationAutomatic
  277.  
  278. Application.EnableEvents = True
  279.  
  280. Application.DisplayStatusBar = True
  281.  
  282. ActiveSheet.DisplayPageBreaks = True
  283.  
  284.  
  285.  
  286. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement