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.

240 lines
7.9 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. # parses description pages, so takes html pages of description pages using soup object, and parses it for info it needs
  7. # stores info it needs in different lists, these lists are returned after being organized
  8. # @param: soup object looking at html page of description page
  9. # return: 'row' that contains a variety of lists that each hold info on the description page
  10. def pabloescobarmarket_description_parser(soup):
  11. # Fields to be parsed
  12. name = "-1" # 0 Product_Name
  13. describe = "-1" # 1 Product_Description
  14. lastSeen = "-1" # 2 Product_LastViewDate
  15. CVE = "-1" # 4 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  16. MS = "-1" # 5 Product_MS_Classification (Microsoft Security)
  17. review = "-1" # 6 Product_Number_Of_Reviews
  18. category = "-1" # 7 Product_Category
  19. shipFrom = "-1" # 8 Product_ShippedFrom
  20. shipTo = "-1" # 9 Product_ShippedTo
  21. left = "-1" # 10 Product_QuantityLeft
  22. escrow = "-1" # 11 Vendor_Warranty
  23. terms = "-1" # 12 Vendor_TermsAndConditions
  24. vendor = "-1" # 13 Vendor_Name
  25. sold = "-1" # 14 Product_QuantitySold
  26. addDate = "-1" # 15 Product_AddedDate
  27. BTC = "-1" # 18 Product_BTC_SellingPrice
  28. USD = "-1" # 19 Product_USD_SellingPrice
  29. rating = "-1" # 20 Vendor_Rating
  30. success = "-1" # 21 Vendor_Successful_Transactions
  31. EURO = "-1" # 22 Product_EURO_SellingPrice
  32. # Finding Product Name
  33. # NA
  34. divmd7 = soup.find('div', {'class': "col-md-7"})
  35. ptag = soup.findAll('p')
  36. # Finding Vendor
  37. vendor = divmd7.find('a').text.strip()
  38. # Finding Vendor Rating
  39. # NA
  40. # Finding Successful Transactions
  41. success = soup.find('span', {'class': "badge-primary"})
  42. # Finding Prices
  43. USD = soup.find('span', {'class': "total"}).text.strip()
  44. BTC = soup.find('div', {'class': "text-center"}).text.strip()
  45. # Finding Escrow
  46. escrow = ptag[-1].text.strip()
  47. # Finding the Product Category
  48. category = ptag[-2].text.strip()
  49. # Finding the Product Quantity Available
  50. # NA
  51. # Finding Number Sold
  52. # NA
  53. # Finding Shipment Information (Origin)
  54. # NA
  55. # Finding Shipment Information (Destination)
  56. # NA
  57. # Finding the Product description
  58. describe = soup.find('div', {'class': "text-white"}).text
  59. describe = describe.replace("\n", " ")
  60. describe = describe.strip()
  61. '''# Finding the Number of Product Reviews
  62. tag = soup.findAll(text=re.compile('Reviews'))
  63. for index in tag:
  64. reviews = index
  65. par = reviews.find('(')
  66. if par >=0:
  67. reviews = reviews.replace("Reviews (","")
  68. reviews = reviews.replace(")","")
  69. reviews = reviews.split(",")
  70. review = str(abs(int(reviews[0])) + abs(int(reviews[1])))
  71. else :
  72. review = "-1"'''
  73. # Searching for CVE and MS categories
  74. cve = soup.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  75. if cve:
  76. CVE = " "
  77. for idx in cve:
  78. CVE += (idx)
  79. CVE += " "
  80. CVE = CVE.replace(',', ' ')
  81. CVE = CVE.replace('\n', '')
  82. ms = soup.findAll(text=re.compile('MS\d{2}-\d{3}'))
  83. if ms:
  84. MS = " "
  85. for im in ms:
  86. MS += (im)
  87. MS += " "
  88. MS = MS.replace(',', ' ')
  89. MS = MS.replace('\n', '')
  90. # Populating the final variable (this should be a list with all fields scraped)
  91. row = (name, describe, lastSeen, CVE, MS, review, category, shipFrom, shipTo, left, escrow, terms, vendor,
  92. sold, addDate, BTC, USD, rating, success, EURO)
  93. # Sending the results
  94. return row
  95. # parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  96. # stores info it needs in different lists, these lists are returned after being organized
  97. # @param: soup object looking at html page of listing page
  98. # return: 'row' that contains a variety of lists that each hold info on the listing page
  99. def pabloescobarmarket_listing_parser(soup):
  100. # Fields to be parsed
  101. nm = 0 # Total_Products (Should be Integer)
  102. mktName = "PabloEscobarMarket" # 0 Marketplace_Name
  103. name = [] # 1 Product_Name
  104. CVE = [] # 2 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  105. MS = [] # 3 Product_MS_Classification (Microsoft Security)
  106. category = [] # 4 Product_Category
  107. describe = [] # 5 Product_Description
  108. escrow = [] # 6 Vendor_Warranty
  109. views = [] # 7 Product_Number_Of_Views
  110. reviews = [] # 8 Product_Number_Of_Reviews
  111. addDate = [] # 9 Product_AddDate
  112. lastSeen = [] # 10 Product_LastViewDate
  113. BTC = [] # 11 Product_BTC_SellingPrice
  114. USD = [] # 12 Product_USD_SellingPrice
  115. EURO = [] # 13 Product_EURO_SellingPrice
  116. sold = [] # 14 Product_QuantitySold
  117. qLeft = [] # 15 Product_QuantityLeft
  118. shipFrom = [] # 16 Product_ShippedFrom
  119. shipTo = [] # 17 Product_ShippedTo
  120. vendor = [] # 18 Vendor
  121. rating = [] # 19 Vendor_Rating
  122. success = [] # 20 Vendor_Successful_Transactions
  123. href = [] # 23 Product_Links (Urls)
  124. listing = soup.findAll('div', {"class": "p-4"})
  125. # Populating the Number of Products
  126. nm = len(listing)
  127. for a in listing:
  128. bae = a.findAll('a', href=True)
  129. # Adding the url to the list of urls
  130. link = bae[0].get('href')
  131. link = cleanLink(link)
  132. href.append(link)
  133. # Finding the Product
  134. product = a.find('h4').text
  135. product = product.replace('\n', ' ')
  136. product = product.replace(",", "")
  137. product = product.replace("...", "")
  138. product = product.strip()
  139. name.append(product)
  140. # Finding Prices
  141. price = a.find('div', {"class": "price"}).text
  142. tempUSD = price.split("~")[0]
  143. tempUSD = tempUSD.replace("$", "")
  144. tempUSD = tempUSD.strip()
  145. USD.append(tempUSD)
  146. tempBTC = price.split("~")[1]
  147. tempBTC = tempBTC.replace("BTC", "")
  148. tempBTC = tempBTC.strip()
  149. BTC.append(tempBTC)
  150. # Finding the Vendor
  151. #NA
  152. # Finding the Category
  153. # NA
  154. # Finding Number Sold and Quantity Left
  155. # NA
  156. # Finding Successful Transactions
  157. # NA
  158. # Searching for CVE and MS categories
  159. cve = a.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  160. if not cve:
  161. cveValue = "-1"
  162. else:
  163. cee = " "
  164. for idx in cve:
  165. cee += (idx)
  166. cee += " "
  167. cee = cee.replace(',', ' ')
  168. cee = cee.replace('\n', '')
  169. cveValue = cee
  170. CVE.append(cveValue)
  171. ms = a.findAll(text=re.compile('MS\d{2}-\d{3}'))
  172. if not ms:
  173. MSValue = "-1"
  174. else:
  175. me = " "
  176. for im in ms:
  177. me += (im)
  178. me += " "
  179. me = me.replace(',', ' ')
  180. me = me.replace('\n', '')
  181. MSValue = me
  182. MS.append(MSValue)
  183. # Populate the final variable (this should be a list with all fields scraped)
  184. return organizeProducts(mktName, nm, name, CVE, MS, category, describe, escrow, views, reviews, addDate, lastSeen,
  185. BTC, USD, EURO, qLeft, shipFrom, shipTo, vendor, rating, success, sold, href)
  186. # called by the crawler to get description links on a listing page
  187. # @param: beautifulsoup object that is using the correct html page (listing page)
  188. # return: list of description links from a listing page FIX
  189. def pabloescobarmarket_links_parser(soup):
  190. # Returning all links that should be visited by the Crawler
  191. href = []
  192. listing = soup.findAll('div', {"class": "p-4"})
  193. for a in listing:
  194. bae = a.find('a', href=True)
  195. link = bae['href']
  196. href.append(link)
  197. return href