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.

220 lines
9.2 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. import re
  7. #parses description pages, so takes html pages of description pages using soup object, and parses it for info it needs
  8. #stores info it needs in different lists, these lists are returned after being organized
  9. #@param: soup object looking at html page of description page
  10. #return: 'row' that contains a variety of lists that each hold info on the description page
  11. def AnonMarket_description_parser(soup):
  12. vendor = "-1" # 0 *Vendor_Name
  13. success = "-1" # 1 Vendor_Successful_Transactions
  14. rating_vendor = "-1" # 2 Vendor_Rating
  15. name = "-1" # 3 *Product_Name
  16. describe = "-1" # 4 Product_Description
  17. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  18. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  19. category = "-1" # 7 Product_Category
  20. views = "-1" # 8 Product_Number_Of_Views
  21. reviews = "-1" # 9 Product_Number_Of_Reviews
  22. rating_item = "-1" # 10 Product_Rating
  23. addDate = "-1" # 11 Product_AddedDate
  24. BTC = "-1" # 12 Product_BTC_SellingPrice
  25. USD = "-1" # 13 Product_USD_SellingPrice
  26. EURO = "-1" # 14 Product_EURO_SellingPrice
  27. sold = "-1" # 15 Product_QuantitySold
  28. left = "-1" # 16 Product_QuantityLeft
  29. shipFrom = "-1" # 17 Product_ShippedFrom
  30. shipTo = "-1" # 18 Product_ShippedTo
  31. image = "-1" # 19 Product_Image
  32. vendor_image = "-1" # 20 Vendor_Image
  33. name_of_product = soup.find("div", {"class": "heading"}).text
  34. name = cleanString(name_of_product.strip())
  35. description_div = soup.find("div", {"class": "tab1"})
  36. if description_div is None:
  37. describe = "-1"
  38. else:
  39. describe = cleanString(description_div.text.strip())
  40. # Finding Product Image
  41. image = soup.find('div', {'class': 'thumbnails'}).find('img')
  42. image = image.get('src')
  43. image = image.split('base64,')[-1]
  44. info_div = soup.find('div', {'class': 'information'})
  45. table = info_div.find('table') if info_div else None
  46. if table:
  47. # Find all table rows
  48. rows = table.find_all('tr')
  49. # Parse each row to get relevant data
  50. data = {}
  51. for row in rows:
  52. columns = row.find_all('td')
  53. if len(columns) == 3:
  54. key = columns[0].text.strip()
  55. value = columns[2].text.strip()
  56. data[key] = value
  57. # Extract specific data from the dictionary and assign them to individual variables
  58. vendor = data.get('Vendor', '-1')
  59. shipFrom = data.get('Location', '-1')
  60. shipTo = data.get('Ships to', '-1')
  61. category = data.get('Category', '-1')
  62. USD = data.get('Price', '-1').split()[0]
  63. left = data.get('Stock', '-1')
  64. # Populating the final variable (this should be a list with all fields scraped)
  65. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  66. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
  67. # Sending the results
  68. return row
  69. #parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  70. #stores info it needs in different lists, these lists are returned after being organized
  71. #@param: soup object looking at html page of listing page
  72. #return: 'row' that contains a variety of lists that each hold info on the listing page
  73. def AnonMarket_listing_parser(soup):
  74. # Fields to be parsed
  75. nm = 0 # *Total_Products (Should be Integer)
  76. mktName = "AnonMarket" # 0 *Marketplace_Name
  77. vendor = [] # 1 *Vendor y
  78. rating_vendor = [] # 2 Vendor_Rating
  79. success = [] # 3 Vendor_Successful_Transactions
  80. name = [] # 4 *Product_Name y
  81. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  82. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  83. category = [] # 7 Product_Category y
  84. describe = [] # 8 Product_Description
  85. views = [] # 9 Product_Number_Of_Views
  86. reviews = [] # 10 Product_Number_Of_Reviews
  87. rating_item = [] # 11 Product_Rating
  88. addDate = [] # 12 Product_AddDate
  89. BTC = [] # 13 Product_BTC_SellingPrice
  90. USD = [] # 14 Product_USD_SellingPrice y
  91. EURO = [] # 15 Product_EURO_SellingPrice
  92. sold = [] # 16 Product_QuantitySold
  93. qLeft =[] # 17 Product_QuantityLeft
  94. shipFrom = [] # 18 Product_ShippedFrom
  95. shipTo = [] # 19 Product_ShippedTo
  96. image = [] # 20 Product_Image
  97. image_vendor = [] # 21 Vendor_Image
  98. href = [] # 22 Product_Links
  99. base_url = "http://2r7wa5og3ly4umqhmmqqytae6bufl5ql5kz7sorndpqtrkc2ri7tohad.onion"
  100. products_list = soup.find_all('div', {'class': 'item'})
  101. nm = 0
  102. for product in products_list:
  103. try:
  104. name_of_product = product.find("div", {"class": "title"}).text.strip()
  105. name.append(name_of_product)
  106. name_of_vendor = product.find("a", {'class': 'seller'}).text.strip()
  107. vendor.append(name_of_vendor)
  108. cat = soup.find("div", {'class': 'heading'}).text
  109. category.append(cat)
  110. product_link_element = product.find("div", {"class": "title"}).find_parent('a')
  111. if product_link_element:
  112. link = product_link_element['href']
  113. if "/product/" in link and "/user/" not in link:
  114. full_link = base_url + link
  115. href.append(full_link)
  116. else:
  117. href.append("-1")
  118. else:
  119. href.append("-1")
  120. # Append '-1' for unavailable data
  121. rating_vendor.append("-1")
  122. success.append("-1")
  123. CVE.append("-1")
  124. MS.append("-1")
  125. describe.append("-1")
  126. views.append("-1")
  127. reviews.append("-1")
  128. addDate.append("-1")
  129. BTC.append("-1")
  130. EURO.append("-1")
  131. sold.append("-1")
  132. qLeft.append("-1")
  133. shipFrom.append("-1")
  134. shipTo.append("-1")
  135. image.append("-1")
  136. image_vendor.append("-1")
  137. nm += 1
  138. except AttributeError as e:
  139. print("I'm somewhere I don't belong. I'm going to leave")
  140. continue
  141. # Populate the final variable (this should be a list with all fields scraped)
  142. return organizeProducts(
  143. marketplace = "AnonMarket",
  144. nm = nm,
  145. vendor = vendor,
  146. rating_vendor = rating_vendor,
  147. success_vendor = success,
  148. nombre = name,
  149. CVE = CVE,
  150. MS = MS,
  151. category = category,
  152. describe = describe,
  153. views = views,
  154. reviews = reviews,
  155. rating_item = rating_item,
  156. addDate = addDate,
  157. BTC = BTC,
  158. USD = USD,
  159. EURO = EURO,
  160. sold = sold,
  161. qLeft = qLeft,
  162. shipFrom = shipFrom,
  163. shipTo = shipTo,
  164. href = href,
  165. image = image,
  166. image_vendor = image_vendor
  167. )
  168. #called by the crawler to get description links on a listing page
  169. #@param: beautifulsoup object that is using the correct html page (listing page)
  170. #return: list of description links from a listing page
  171. def AnonMarket_links_parser(soup):
  172. # Base URL to prepend to each product link
  173. base_url = "http://2r7wa5og3ly4umqhmmqqytae6bufl5ql5kz7sorndpqtrkc2ri7tohad.onion"
  174. # Returning all links that should be visited by the Crawler
  175. href = []
  176. # Using a shorter, but still unique, class name
  177. listing = soup.find('div', {'class': 'items'}).find_all('a', href=True, attrs={'href': lambda x: "/product/" in x})
  178. for a in listing:
  179. link = a.get('href')
  180. if link: # Checks if 'href' attribute is not None
  181. # Prepending the base URL to the scraped link
  182. full_link = base_url + link
  183. href.append(full_link)
  184. # Filtering out any links that might not have '/product/' in them
  185. product_links = [link for link in href if '/product/' in link]
  186. return product_links