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.

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