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.

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