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.

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