this is based on calsyslab project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
7.4 KiB

  1. __author__ = 'DarkWeb'
  2. # Here, we are importing the auxiliary functions to clean or convert data
  3. from MarketPlaces.Utilities.utilities import *
  4. # Here, we are importing BeautifulSoup to search through the HTML tree
  5. from bs4 import BeautifulSoup
  6. # This is the method to parse the Description Pages (one page to each Product in the Listing Pages)
  7. def hiddenmarket_description_parser(soup):
  8. # Fields to be parsed
  9. vendor = "-1" # 0 *Vendor_Name
  10. success = "-1" # 1 Vendor_Successful_Transactions
  11. rating_vendor = "-1" # 2 Vendor_Rating
  12. name = "-1" # 3 *Product_Name
  13. describe = "-1" # 4 Product_Description
  14. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  15. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  16. category = "-1" # 7 Product_Category
  17. views = "-1" # 8 Product_Number_Of_Views
  18. reviews = "-1" # 9 Product_Number_Of_Reviews
  19. rating_item = "-1" # 10 Product_Rating
  20. addDate = "-1" # 11 Product_AddedDate
  21. BTC = "-1" # 12 Product_BTC_SellingPrice
  22. USD = "-1" # 13 Product_USD_SellingPrice
  23. EURO = "-1" # 14 Product_EURO_SellingPrice
  24. sold = "-1" # 15 Product_QuantitySold
  25. left = "-1" # 16 Product_QuantityLeft
  26. shipFrom = "-1" # 17 Product_ShippedFrom
  27. shipTo = "-1" # 18 Product_ShippedTo
  28. bae = soup.find('div', {'class': "col-9"})
  29. # Finding Product Name
  30. name = bae.find('h2').text
  31. name = name.replace('\n', ' ')
  32. name = name.replace(",", "")
  33. name = name.strip()
  34. mb = bae.findAll('div', {"class": "mb-1"})
  35. # Finding Vendor
  36. vendor = mb[0].text
  37. vendor = vendor.replace(",", "")
  38. vendor = vendor.replace("Sold by:", "")
  39. vendor = vendor.strip()
  40. # # Finding Vendor Rating
  41. # full_stars = bae[2].find_all('i', {'class': "fas fa-star"})
  42. # half_star = bae[2].find('i', {'class': "fas fa-star-half-alt"})
  43. # rating = len(full_stars) + (0.5 if half_star is not None else 0)
  44. # Finding Quantity Sold and Left
  45. temp = mb[4].text.split(',')
  46. sold = temp[0].replace("sold", "")
  47. sold = sold.strip()
  48. left = temp[1].replace("in stock", "")
  49. left = left.strip()
  50. # Finding USD
  51. USD = bae.find('div', {"class": "h3 text-secondary"}).text
  52. USD = USD.replace("$", "")
  53. USD = USD.strip()
  54. # Finding BTC
  55. temp = bae.find('div', {"class": "small"}).text.split("BTC")
  56. BTC = temp[0].strip()
  57. # shipping_info = bae[4].text
  58. # if "Digital" not in shipping_info:
  59. # shipping_info = shipping_info.split(" ")
  60. #
  61. # # Finding Shipment Information (Origin)
  62. # shipFrom = shipping_info[0].strip()
  63. #
  64. # # Finding Shipment Information (Destination)
  65. # shipTo = shipping_info[1].strip()
  66. # Finding the Product description
  67. describe = bae.find('div', {"class": "card border-top-0"}).text
  68. describe = describe.replace("\n", " ")
  69. describe = describe.replace("\r", " ")
  70. describe = describe.strip()
  71. # Searching for CVE and MS categories
  72. cve = soup.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  73. if cve:
  74. CVE = " "
  75. for idx in cve:
  76. CVE += (idx)
  77. CVE += " "
  78. CVE = CVE.replace(',', ' ')
  79. CVE = CVE.replace('\n', '')
  80. ms = soup.findAll(text=re.compile('MS\d{2}-\d{3}'))
  81. if ms:
  82. MS = " "
  83. for im in ms:
  84. MS += (im)
  85. MS += " "
  86. MS = MS.replace(',', ' ')
  87. MS = MS.replace('\n', '')
  88. # Populating the final variable (this should be a list with all fields scraped)
  89. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  90. BTC, USD, EURO, sold, left, shipFrom, shipTo)
  91. # Sending the results
  92. return row
  93. # This is the method to parse the Listing Pages
  94. def hiddenmarket_listing_parser(soup):
  95. # Fields to be parsed
  96. nm = 0 # *Total_Products (Should be Integer)
  97. mktName = "HiddenMarket" # 0 *Marketplace_Name
  98. vendor = [] # 1 *Vendor y
  99. rating_vendor = [] # 2 Vendor_Rating
  100. success = [] # 3 Vendor_Successful_Transactions
  101. name = [] # 4 *Product_Name y
  102. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  103. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  104. category = [] # 7 Product_Category y
  105. describe = [] # 8 Product_Description
  106. views = [] # 9 Product_Number_Of_Views
  107. reviews = [] # 10 Product_Number_Of_Reviews
  108. rating_item = [] # 11 Product_Rating
  109. addDate = [] # 12 Product_AddDate
  110. BTC = [] # 13 Product_BTC_SellingPrice
  111. USD = [] # 14 Product_USD_SellingPrice y
  112. EURO = [] # 15 Product_EURO_SellingPrice
  113. sold = [] # 16 Product_QuantitySold
  114. qLeft = [] # 17 Product_QuantityLeft
  115. shipFrom = [] # 18 Product_ShippedFrom
  116. shipTo = [] # 19 Product_ShippedTo
  117. href = [] # 20 Product_Links
  118. listing = soup.findAll('div', {"class": "card product-card mb-3"})
  119. # Populating the Number of Products
  120. nm = len(listing)
  121. # Finding Category
  122. cat = soup.find("div", {"class": "col-9"})
  123. cat = cat.find("h2").text
  124. cat = cat.replace("Category: ", "")
  125. cat = cat.replace(",", "")
  126. cat = cat.strip()
  127. for card in listing:
  128. category.append(cat)
  129. bae = card.findAll('a')
  130. # Adding the url to the list of urls
  131. link = bae[0].get('href')
  132. href.append(link)
  133. # Finding Product Name
  134. product = bae[1].text
  135. product = product.replace('\n', ' ')
  136. product = product.replace(",", "")
  137. product = product.strip()
  138. name.append(product)
  139. # Finding Vendor
  140. vendor_name = bae[2].text
  141. vendor_name = vendor_name.replace(",", "")
  142. vendor_name = vendor_name.strip()
  143. vendor.append(vendor_name)
  144. # Finding USD
  145. usd = card.find('div', {"class": "mb-1"}).text
  146. usd = usd.replace("$", "")
  147. usd = usd.strip()
  148. USD.append(usd)
  149. # Finding Reviews
  150. num = card.find("span", {"class": "rate-count"}).text
  151. num = num.replace("(", "")
  152. num = num.replace("review)", "")
  153. num = num.replace("reviews)", "")
  154. num = num.strip()
  155. reviews.append(num)
  156. # Searching for CVE and MS categories
  157. cve = card.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  158. if not cve:
  159. cveValue = "-1"
  160. else:
  161. cee = " "
  162. for idx in cve:
  163. cee += (idx)
  164. cee += " "
  165. cee = cee.replace(',', ' ')
  166. cee = cee.replace('\n', '')
  167. cveValue = cee
  168. CVE.append(cveValue)
  169. ms = card.findAll(text=re.compile('MS\d{2}-\d{3}'))
  170. if not ms:
  171. MSValue = "-1"
  172. else:
  173. me = " "
  174. for im in ms:
  175. me += (im)
  176. me += " "
  177. me = me.replace(',', ' ')
  178. me = me.replace('\n', '')
  179. MSValue = me
  180. MS.append(MSValue)
  181. # Populate the final variable (this should be a list with all fields scraped)
  182. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  183. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href)
  184. def hiddenmarket_links_parser(soup):
  185. # Returning all links that should be visited by the Crawler
  186. href = []
  187. listing = soup.findAll('div', {"class": "item"})
  188. for div in listing:
  189. link = div.find('a')['href']
  190. href.append(link)
  191. return href