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.

227 lines
10 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 abacus_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. product_info = soup.find('div', {'class': '2xl:self-start w-full h-full'})
  34. about_vendor = soup.find('div', {'class': 'px-0.5 py-1 flex flex-col items-center gap-2 text-[13px]'})
  35. try:
  36. ven_temp = about_vendor.find('div', {'class': 'flex items-center gap-0.5'}).find('a').text
  37. ven_temp_list = ven_temp.split(' ')
  38. if len(ven_temp_list) > 1:
  39. ven_temp_list = ven_temp_list[:-1]
  40. ven_temp = ' '.join(ven_temp_list)
  41. vendor = cleanString(ven_temp.strip())
  42. except:
  43. vendor = '-1'
  44. print(vendor)
  45. success = "-1"
  46. try:
  47. rating = about_vendor.find('div', {'class':'font-bold rounded px-2'}).text
  48. rating_list = rating.split(' ')
  49. rating = rating_list[0]
  50. rating = rating.replace('%', '')
  51. except:
  52. rating = '-1'
  53. rating_vendor = rating
  54. print(rating_vendor)
  55. name = product_info.find('div', {'class': 'w-full flex gap-0.5 items-center border-solid border-0 border-border border-b group-hover:border-abacus2 text-sm font-bold justify-center 2xl:justify-start py-1 leading-tight'})
  56. name = cleanString(name.strip())
  57. try:
  58. description = soup.find('div', {'class': 'hidden gap-2 flex-col w-0 p-3 anim anim-FadeIn'}).find('div', {'class':'text-xs w-full text-left text-black'}).text
  59. description = cleanString(description.strip())
  60. except:
  61. description = '-1'
  62. describe = description
  63. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  64. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  65. category = "-1" # 7 Product_Category
  66. views = "-1" # 8 Product_Number_Of_Views
  67. reviews = "-1" # 9 Product_Number_Of_Reviews
  68. rating_item = "-1" # 10 Product_Rating
  69. addDate = "-1" # 11 Product_AddedDate
  70. BTC = "-1" # 12 Product_BTC_SellingPrice
  71. USD = "-1" # 13 Product_USD_SellingPrice
  72. EURO = "-1" # 14 Product_EURO_SellingPrice
  73. sold = "-1" # 15 Product_QuantitySold
  74. left = "-1" # 16 Product_QuantityLeft
  75. shipFrom = "-1" # 17 Product_ShippedFrom
  76. shipTo = "-1" # 18 Product_ShippedTo
  77. image = "-1" # 19 Product_Image
  78. vendor_image = "-1" # 20 Vendor_Image
  79. # Populating the final variable (this should be a list with all fields scraped)
  80. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  81. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
  82. # Sending the results
  83. return row
  84. # parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  85. # stores info it needs in different lists, these lists are returned after being organized
  86. # @param: soup object looking at html page of listing page
  87. # return: 'row' that contains a variety of lists that each hold info on the listing page
  88. def abacus_listing_parser(soup):
  89. # Fields to be parsed
  90. nm = 0 # *Total_Products (Should be Integer)
  91. mktName = "Abacus" # 0 *Marketplace_Name
  92. vendor = [] # 1 *Vendor y
  93. rating_vendor = [] # 2 Vendor_Rating
  94. success = [] # 3 Vendor_Successful_Transactions
  95. name = [] # 4 *Product_Name y
  96. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures) dont worry about this
  97. MS = [] # 6 Product_MS_Classification (Microsoft Security) dont worry about this
  98. category = [] # 7 Product_Category y
  99. describe = [] # 8 Product_Description
  100. views = [] # 9 Product_Number_Of_Views
  101. reviews = [] # 10 Product_Number_Of_Reviews
  102. rating_item = [] # 11 Product_Rating
  103. addDate = [] # 12 Product_AddDate
  104. BTC = [] # 13 Product_BTC_SellingPrice
  105. USD = [] # 14 Product_USD_SellingPrice y
  106. EURO = [] # 15 Product_EURO_SellingPrice
  107. sold = [] # 16 Product_QuantitySold
  108. qLeft = [] # 17 Product_QuantityLeft
  109. shipFrom = [] # 18 Product_ShippedFrom
  110. shipTo = [] # 19 Product_ShippedTo
  111. image = [] # 20 Product_Image
  112. image_vendor = [] # 21 Vendor_Image
  113. href = [] # 22 Product_Links
  114. cat = soup.find('span', {"class": "btn btn-sm btn-outline-dark w-100 active"}).text
  115. cat = cleanString(cat).strip()
  116. listing = soup.find('div', {"class": 'card-body text-black text-left bg-dark'}).findAll('div', {"class": 'card mb-4 border-danger rounded-0'})
  117. # Populating the Number of Products
  118. nm = len(listing)
  119. for a in listing:
  120. category.append(cat)
  121. # Adding the url to the list of urls
  122. link = a.find('a', {'class': "badge badge-danger w-100 text-white"}).get('href')
  123. link = cleanLink(link)
  124. href.append(link)
  125. # Finding the Product name
  126. product = a.find('div', {"class": 'marquee-parent'}).find('div', {"class": "marquee-child"}).text
  127. product = product.replace('\n', ' ')
  128. product = product.replace(",", "")
  129. product = product.replace("...", "")
  130. product = product.strip()
  131. name.append(product)
  132. # Finding Product Image
  133. product_image = a.find('img')
  134. product_image = product_image.get('src')
  135. product_image = product_image.split('base64,')[-1]
  136. image.append(product_image)
  137. # Finding Prices
  138. price = a.findAll('a', {"class": "text-white"})[-1].text
  139. price = price.replace("$","")
  140. price = price.strip()
  141. USD.append(price)
  142. # Finding Item Rating
  143. temp = a.find('small', {"class": "text-white"})
  144. rating = len(temp.findAll('i', {"class": "fas fa-star"}))
  145. half_stars = len(temp.findAll('i', {'class': "fas fa-star-half-alt"}))
  146. if half_stars > 0:
  147. rating += 0.5
  148. rating_item.append(str(rating))
  149. # Finding the Vendor
  150. vendor_name = a.find('a', {"class": 'badge badge-dark w-100 text-white my-1'}).text
  151. vendor_name = vendor_name.replace(",", "")
  152. vendor_name = vendor_name.strip()
  153. vendor.append(vendor_name)
  154. image_vendor.append("-1")
  155. # Searching for CVE and MS categories
  156. cve = a.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  157. if not cve:
  158. cveValue = "-1"
  159. else:
  160. cee = " "
  161. for idx in cve:
  162. cee += (idx)
  163. cee += " "
  164. cee = cee.replace(',', ' ')
  165. cee = cee.replace('\n', '')
  166. cveValue = cee
  167. CVE.append(cveValue)
  168. ms = a.findAll(text=re.compile('MS\d{2}-\d{3}'))
  169. if not ms:
  170. MSValue = "-1"
  171. else:
  172. me = " "
  173. for im in ms:
  174. me += (im)
  175. me += " "
  176. me = me.replace(',', ' ')
  177. me = me.replace('\n', '')
  178. MSValue = me
  179. MS.append(MSValue)
  180. # Populate the final variable (this should be a list with all fields scraped)
  181. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  182. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image, image_vendor)
  183. # called by the crawler to get description links on a listing page
  184. # @param: beautifulsoup object that is using the correct html page (listing page)
  185. # return: list of description links from a listing page
  186. def abacus_links_parser(soup):
  187. # Returning all links that should be visited by the Crawler
  188. href = []
  189. listing = soup.findAll('div', {"class": "src-listing p-1 pb-0 flex flex-col justify-between w-full rounded-md border-solid border-[1px] !border-border !bg-white hover:!bg-hover hover:!border-abacus2 !mt-0"})
  190. for a in listing:
  191. link = a.find('a', href=True).get('href')
  192. href.append(link)
  193. return href