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.

223 lines
9.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
  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 darkmarket_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)
  19. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  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. image = "-1" # 19 Product_Image
  33. vendor_image = "-1" # 20 Vendor_Image
  34. #Dark Market no vendor
  35. '''
  36. divmd7 = soup.find('div', {'class': "col-md-7"})
  37. # Finding Vendor
  38. vendor = divmd7.find('a').text.strip()
  39. '''
  40. #Finding Product name
  41. name = soup.find('h1', {'class': "entry-title"}).text.strip()
  42. # Finding Prices
  43. USD = soup.find('span', {'class': "woocommerce-Price-currencySymbol"}).text.strip()
  44. # Finding Product Image
  45. image = soup.find('img', {'class': 'wp-post-image'})
  46. image = image.get('src')
  47. image = image.split('base64,')[-1]
  48. # Finding the Product description
  49. describe = soup.find('div', {'class': "woocommerce-Tabs-panel--description"}).text
  50. describe = cleanString(describe.strip())
  51. #Gets rid of the Description word (the first <p>)
  52. describe = describe[11:]
  53. #Finding Category
  54. category = soup.find('a', {'rel': 'tag'}).text.strip()
  55. #Finding number of product reviews
  56. reviews = soup.find('span', class_="count").text.strip()
  57. #Finding producting rating
  58. rating_item = soup.find('strong', {'class': 'rating'}).text.strip()
  59. # Searching for CVE and MS categories
  60. cve = soup.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  61. if cve:
  62. CVE = " "
  63. for idx in cve:
  64. CVE += (idx)
  65. CVE += " "
  66. CVE = CVE.replace(',', ' ')
  67. CVE = CVE.replace('\n', '')
  68. ms = soup.findAll(text=re.compile('MS\d{2}-\d{3}'))
  69. if ms:
  70. MS = " "
  71. for im in ms:
  72. MS += (im)
  73. MS += " "
  74. MS = MS.replace(',', ' ')
  75. MS = MS.replace('\n', '')
  76. # Populating the final variable (this should be a list with all fields scraped)
  77. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  78. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
  79. # Sending the results
  80. return row
  81. #parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  82. #stores info it needs in different lists, these lists are returned after being organized
  83. #@param: soup object looking at html page of listing page
  84. #return: 'row' that contains a variety of lists that each hold info on the listing page
  85. def darkmarket_listing_parser(soup):
  86. # Fields to be parsed
  87. nm = 0 # *Total_Products (Should be Integer)
  88. mktName = "DarkMarket" # 0 *Marketplace_Name
  89. vendor = [] # 1 *Vendor y
  90. rating_vendor = [] # 2 Vendor_Rating
  91. success = [] # 3 Vendor_Successful_Transactions
  92. name = [] # 4 *Product_Name y
  93. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures) dont worry about this
  94. MS = [] # 6 Product_MS_Classification (Microsoft Security) dont worry about this
  95. category = [] # 7 Product_Category y
  96. describe = [] # 8 Product_Description
  97. views = [] # 9 Product_Number_Of_Views
  98. reviews = [] # 10 Product_Number_Of_Reviews
  99. rating_item = [] # 11 Product_Rating
  100. addDate = [] # 12 Product_AddDate
  101. BTC = [] # 13 Product_BTC_SellingPrice
  102. USD = [] # 14 Product_USD_SellingPrice y
  103. EURO = [] # 15 Product_EURO_SellingPrice
  104. sold = [] # 16 Product_QuantitySold
  105. qLeft = [] # 17 Product_QuantityLeft
  106. shipFrom = [] # 18 Product_ShippedFrom
  107. shipTo = [] # 19 Product_ShippedTo
  108. image = [] # 20 Product_Image
  109. image_vendor = [] # 21 Vendor_Image
  110. href = [] # 22 Product_Links
  111. listing = soup.findAll('li', {"class": ["type-product", "product"]})
  112. # Populating the Number of Products
  113. nm = len(listing)
  114. for a in listing:
  115. bae = a.findAll('a', href=True)
  116. # Adding the url to the list of urls (Product Links)
  117. link = bae[0].get('href')
  118. href.append(link)
  119. # Category
  120. temp_category = soup.find('h1', {'class': 'page-title'}).text.strip()
  121. category.append(temp_category)
  122. # Product Name
  123. product = a.find('h2', {"class": "woocommerce-loop-product__title"}).text
  124. product = product.replace('\n', ' ')
  125. product = product.replace(",", "")
  126. product = product.replace("...", "")
  127. product = product.strip()
  128. name.append(product)
  129. # USD Price
  130. price = a.find('span', {"class": "woocommerce-Price-currencySymbol"})
  131. if "$" in price:
  132. tempUSD = price.next_sibling.strip()
  133. #tempUSD = price.get_next
  134. USD.append(tempUSD)
  135. else:
  136. USD.append("-1")
  137. # Img
  138. product_image = a.find('img', class_='attachment-woocommerce_thumbnail')
  139. product_image = product_image.get('src')
  140. #print("src ", str(product_image))
  141. product_image = product_image.split('base64,')[-1]
  142. #print("listing ", str(product_image)[0:30])
  143. image.append(product_image)
  144. # Searching for CVE and MS categories
  145. cve = a.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  146. if not cve:
  147. cveValue="-1"
  148. else:
  149. cee = " "
  150. for idx in cve:
  151. cee += (idx)
  152. cee += " "
  153. cee = cee.replace(',', ' ')
  154. cee = cee.replace('\n', '')
  155. cveValue=cee
  156. CVE.append(cveValue)
  157. ms = a.findAll(text=re.compile('MS\d{2}-\d{3}'))
  158. if not ms:
  159. MSValue="-1"
  160. else:
  161. me = " "
  162. for im in ms:
  163. me += (im)
  164. me += " "
  165. me = me.replace(',', ' ')
  166. me = me.replace('\n', '')
  167. MSValue=me
  168. MS.append(MSValue)
  169. # Populate the final variable (this should be a list with all fields scraped)
  170. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  171. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image, image_vendor)
  172. #called by the crawler to get description links on a listing page
  173. #@param: beautifulsoup object that is using the correct html page (listing page)
  174. #return: list of description links from a listing page
  175. def darkmarket_links_parser(soup):
  176. # Returning all links that should be visited by the Crawler
  177. href = []
  178. listing = soup.find_all('li', class_=["product", "type-product"])
  179. for a in listing:
  180. bae = a.find('a', href=True)
  181. link = bae['href']
  182. href.append(link)
  183. return href