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.

181 lines
8.0 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, ResultSet, Tag
  6. # This is the method to parse the Description Pages (one page to each Product in the Listing Pages)
  7. def darkmarket_description_parser(soup: BeautifulSoup):
  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. image = "-1"
  29. image_vendor = "-1"
  30. details: Tag = soup.find("div", {"class": "wc-content"})
  31. vendor = details.find("div", {"class": "product_meta"}).find("a", {"class": "wcvendors_cart_sold_by_meta"}).text
  32. name = details.find("h1", {"class": "product_title entry-title"}).text
  33. describe_list = [
  34. elem.text for elem in
  35. details.find("div", {"id": "tab-description"}).find_all()
  36. if elem.name != "h2"
  37. ]
  38. describe = " ".join(describe_list)
  39. categories_list: ResultSet[Tag] = details.find("span", {"class": "posted_in"}).find_all("a")
  40. category = "Hacking"
  41. reviews = details.find("div", {"class": "review-link"}).get("title")
  42. rating_item = details.find("div", {"class": "star-rating"}).get('title')
  43. price_container = details.find("p", {"class": "price"})
  44. if not price_container.find("ins"):
  45. USD = price_container.find("span", {"class": "woocommerce-Price-amount amount"}).text.replace("$", "")
  46. else:
  47. USD = price_container.find("ins").find("span", {"class": "woocommerce-Price-amount amount"}).text.replace("$", "")
  48. # print(f"\n[desc] Product: {name}")
  49. # print(f"[desc] Price: ${USD}\n")
  50. # Populating the final variable (this should be a list with all fields scraped)
  51. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  52. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, image_vendor)
  53. # Sending the results
  54. return row
  55. # This is the method to parse the Listing Pages
  56. def darkmarket_listing_parser(soup: BeautifulSoup):
  57. # Fields to be parsed
  58. nm = 0 # *Total_Products (Should be Integer)
  59. mktName = "TheDarkMarket" # 0 *Marketplace_Name
  60. vendor = [] # 1 *Vendor y
  61. rating_vendor = [] # 2 Vendor_Rating
  62. success = [] # 3 Vendor_Successful_Transactions
  63. name = [] # 4 *Product_Name y
  64. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  65. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  66. category = [] # 7 Product_Category y
  67. describe = [] # 8 Product_Description
  68. views = [] # 9 Product_Number_Of_Views
  69. reviews = [] # 10 Product_Number_Of_Reviews
  70. rating_item = [] # 11 Product_Rating
  71. addDate = [] # 12 Product_AddDate
  72. BTC = [] # 13 Product_BTC_SellingPrice
  73. USD = [] # 14 Product_USD_SellingPrice y
  74. EURO = [] # 15 Product_EURO_SellingPrice
  75. sold = [] # 16 Product_QuantitySold
  76. qLeft =[] # 17 Product_QuantityLeft
  77. shipFrom = [] # 18 Product_ShippedFrom
  78. shipTo = [] # 19 Product_ShippedTo
  79. image = []
  80. image_vendor = []
  81. href = [] # 20 Product_Links
  82. products_list: ResultSet[Tag] = soup.find("ul", {"class": "products columns-3"}).find_all("li")
  83. for product in products_list:
  84. nm += 1
  85. product_vendor = product.find("small", {"class": "wcvendors_sold_by_in_loop"}).find("a").text
  86. vendor.append(cleanString(product_vendor))
  87. # rating_vendor.append("-1")
  88. # success.append("-1")
  89. product_name = product.find("h2", {"class": "woocommerce-loop-product__title"}).text
  90. name.append(cleanString(product_name))
  91. # CVE.append("-1")
  92. # MS.append("-1")
  93. product_category = product.find("div", {"class": 'product-categories'}).text
  94. category.append(cleanString(product_category))
  95. # describe.append("-1")
  96. # views.append("-1")
  97. # reviews.append("-1")
  98. product_rating = product.find("div", {"class": "star-rating"}).get("title")
  99. rating_item.append(cleanString(product_rating))
  100. # addDate.append(datetime.now().strftime("%m/%d/%Y "))
  101. # BTC.append("-1")
  102. price_container = product.find("span", {"class": "price"})
  103. if not price_container.find("ins"):
  104. product_price = price_container.find("span", {"class": "woocommerce-Price-amount amount"}).text.replace("$", "")
  105. else:
  106. product_price = price_container.find("ins").find("span", {"class": "woocommerce-Price-amount amount"}).text.replace("$", "")
  107. USD.append(cleanNumbers(product_price))
  108. # EURO.append("-1")
  109. # sold.append("-1")
  110. # qLeft.append("-1")
  111. # shipTo.append("-1")
  112. # shipFrom.append("-1")
  113. product_href = product.find("a", {"class": "woocommerce-LoopProduct-link woocommerce-loop-product__link"}).get("href")
  114. href.append(product_href)
  115. # print(f"\n[list] Product: {product_name}")
  116. # print(f"[list] Links: ${product_href}\n")
  117. product_images_list = product.find("a", {"class": "tf-loop-product-thumbs-link"}).find("img").get("data-srcset").split(" ")
  118. product_image = product_images_list[0]
  119. image.append(product_image)
  120. # Populate the final variable (this should be a list with all fields scraped)
  121. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  122. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image,
  123. image_vendor)
  124. def darkmarket_links_parser(soup: BeautifulSoup):
  125. # Returning all links that should be visited by the Crawler
  126. href = []
  127. listing: ResultSet[Tag] = soup.find("ul", {"class": "products columns-3"}).find_all("li")
  128. for li in listing:
  129. a = li.find('a', {"class": "woocommerce-LoopProduct-link woocommerce-loop-product__link"})
  130. link = a.get('href')
  131. href.append(link)
  132. print(f"Links: {href}")
  133. return href