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.

231 lines
8.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  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. # This is the method to parse the Description Pages (one page to each Product in the Listing Pages)
  7. def quest_description_parser(soup):
  8. # Fields to be parsed
  9. vendor = "-1" # 0 *Vendor_Name
  10. success = "-1" # 1 Vendor_Successful_Transactions
  11. rating_vendor = "-1" # 2 Vendor_Rating
  12. name = "-1" # 3 *Product_Name
  13. describe = "-1" # 4 Product_Description
  14. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  15. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  16. category = "-1" # 7 Product_Category
  17. views = "-1" # 8 Product_Number_Of_Views
  18. reviews = "-1" # 9 Product_Number_Of_Reviews
  19. rating_item = "-1" # 10 Product_Rating
  20. addDate = "-1" # 11 Product_AddedDate
  21. BTC = "-1" # 12 Product_BTC_SellingPrice
  22. USD = "-1" # 13 Product_USD_SellingPrice
  23. EURO = "-1" # 14 Product_EURO_SellingPrice
  24. sold = "-1" # 15 Product_QuantitySold
  25. left = "-1" # 16 Product_QuantityLeft
  26. shipFrom = "-1" # 17 Product_ShippedFrom
  27. shipTo = "-1" # 18 Product_ShippedTo
  28. row = soup.find_all('div', {'class': "row"})
  29. # Finding Product Name
  30. name = row[1].text
  31. name = name.replace('\n', ' ')
  32. name = name.replace(",", "")
  33. name = name.strip()
  34. small = row[3].find_all('small')
  35. # Finding Vendor
  36. vendor = small[0].text
  37. vendor = vendor.replace("Vendor:", "")
  38. vendor = vendor.replace(",", "")
  39. vendor = vendor.strip()
  40. # Finding Vendor Rating
  41. full_stars = small[2].find_all('i', {'class': "fas fa-star"})
  42. half_star = small[2].find('i', {'class': "fas fa-star-half-alt"})
  43. rating_vendor = len(full_stars) + (0.5 if half_star is not None else 0)
  44. # Finding Successful Transactions
  45. success = small[4].text
  46. success = success.replace("Total Sales:", "")
  47. success = success.strip()
  48. small = row[2].find('p', {'class': "text-left"}).find_all('small')
  49. # Finding Prices
  50. USD = small[1].text
  51. USD = USD.replace("$", "")
  52. USD = USD.strip()
  53. shipping_info = row[2].find('p', {'class': "text-left"}).find('span').text.strip()
  54. if "Digital" not in shipping_info:
  55. shipping_info = shipping_info.split(" ")
  56. # Finding Shipment Information (Origin)
  57. shipFrom = shipping_info[0].strip()
  58. # Finding Shipment Information (Destination)
  59. shipTo = shipping_info[1].strip()
  60. textarea = row[2].find_all('textarea')
  61. # Finding the Product description
  62. describe = textarea[0].text
  63. describe = describe.replace("\n", " ")
  64. describe = describe.replace("\r", " ")
  65. describe = describe.strip()
  66. '''
  67. # Finding the Number of Product Reviews
  68. tag = soup.findAll(text=re.compile('Reviews'))
  69. for index in tag:
  70. reviews = index
  71. par = reviews.find('(')
  72. if par >=0:
  73. reviews = reviews.replace("Reviews (","")
  74. reviews = reviews.replace(")","")
  75. reviews = reviews.split(",")
  76. review = str(abs(int(reviews[0])) + abs(int(reviews[1])))
  77. else :
  78. review = "-1"
  79. '''
  80. # Searching for CVE and MS categories
  81. cve = soup.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  82. if cve:
  83. CVE = " "
  84. for idx in cve:
  85. CVE += (idx)
  86. CVE += " "
  87. CVE = CVE.replace(',', ' ')
  88. CVE = CVE.replace('\n', '')
  89. ms = soup.findAll(text=re.compile('MS\d{2}-\d{3}'))
  90. if ms:
  91. MS = " "
  92. for im in ms:
  93. MS += (im)
  94. MS += " "
  95. MS = MS.replace(',', ' ')
  96. MS = MS.replace('\n', '')
  97. # Populating the final variable (this should be a list with all fields scraped)
  98. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  99. BTC, USD, EURO, sold, left, shipFrom, shipTo)
  100. # Sending the results
  101. return row
  102. # This is the method to parse the Listing Pages
  103. def quest_listing_parser(soup):
  104. # Fields to be parsed
  105. nm = 0 # *Total_Products (Should be Integer)
  106. mktName = "Quest" # 0 *Marketplace_Name
  107. vendor = [] # 1 *Vendor y
  108. rating_vendor = [] # 2 Vendor_Rating
  109. success = [] # 3 Vendor_Successful_Transactions
  110. name = [] # 4 *Product_Name y
  111. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  112. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  113. category = [] # 7 Product_Category y
  114. describe = [] # 8 Product_Description
  115. views = [] # 9 Product_Number_Of_Views
  116. reviews = [] # 10 Product_Number_Of_Reviews
  117. rating_item = [] # 11 Product_Rating
  118. addDate = [] # 12 Product_AddDate
  119. BTC = [] # 13 Product_BTC_SellingPrice
  120. USD = [] # 14 Product_USD_SellingPrice y
  121. EURO = [] # 15 Product_EURO_SellingPrice
  122. sold = [] # 16 Product_QuantitySold
  123. qLeft =[] # 17 Product_QuantityLeft
  124. shipFrom = [] # 18 Product_ShippedFrom
  125. shipTo = [] # 19 Product_ShippedTo
  126. href = [] # 20 Product_Links
  127. # Finding category of listing page
  128. cat = soup.find('span', {'class': "btn btn-sm btn-outline-mgray active border-info"}).text
  129. cat = cat.replace("Digital -", "")
  130. cat = cat.strip()
  131. listing = soup.find_all('div', {"class": "col-md-2 my-md-0 col-12"})
  132. # Populating the Number of Products
  133. nm = len(listing)
  134. for a in listing:
  135. bae = a.find_all('a', href=True)
  136. # Adding the category
  137. category.append(cat)
  138. # Adding the url to the list of urls
  139. link = bae[0].get('href')
  140. link = cleanLink(link)
  141. href.append(link)
  142. # Finding the Vendor
  143. vendor_name = bae[2].text
  144. vendor_name = vendor_name.replace(",", "")
  145. vendor_name = vendor_name.strip()
  146. vendor.append(vendor_name)
  147. # Finding the Product
  148. product = bae[1].find('img').get('alt')
  149. product = product.replace('\n', ' ')
  150. product = product.replace(",", "")
  151. product = product.strip()
  152. name.append(product)
  153. # Searching for CVE and MS categories
  154. cve = a.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  155. if not cve:
  156. cveValue="-1"
  157. else:
  158. cee = " "
  159. for idx in cve:
  160. cee += (idx)
  161. cee += " "
  162. cee = cee.replace(',', ' ')
  163. cee = cee.replace('\n', '')
  164. cveValue=cee
  165. CVE.append(cveValue)
  166. ms = a.findAll(text=re.compile('MS\d{2}-\d{3}'))
  167. if not ms:
  168. MSValue="-1"
  169. else:
  170. me = " "
  171. for im in ms:
  172. me += (im)
  173. me += " "
  174. me = me.replace(',', ' ')
  175. me = me.replace('\n', '')
  176. MSValue=me
  177. MS.append(MSValue)
  178. # Populate the final variable (this should be a list with all fields scraped)
  179. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  180. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href)
  181. def quest_links_parser(soup):
  182. # Returning all links that should be visited by the Crawler
  183. href = []
  184. listing = soup.findAll('div', {"class": "col-md-2 my-md-0 col-12"})
  185. for div in listing:
  186. link = div.find('a')["href"]
  187. href.append(link)
  188. return href