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.

188 lines
7.0 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. import re
  7. #parses description pages, so takes html pages of description pages using soup object, and parses it for info it needs
  8. #stores info it needs in different lists, these lists are returned after being organized
  9. #@param: soup object looking at html page of description page
  10. #return: 'row' that contains a variety of lists that each hold info on the description page
  11. def nexus_description_parser(soup):
  12. # Fields to be parsed
  13. vendor = "-1" # 0 *Vendor_Name
  14. success = "-1" # 1 Vendor_Successful_Transactions
  15. rating_vendor = "-1" # 2 Vendor_Rating
  16. name = "-1" # 3 *Product_Name
  17. describe = "-1" # 4 Product_Description
  18. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures) dont worry about that much
  19. MS = "-1" # 6 Product_MS_Classification (Microsoft Security) dont worry about that much
  20. category = "-1" # 7 Product_Category
  21. views = "-1" # 8 Product_Number_Of_Views
  22. reviews = "-1" # 9 Product_Number_Of_Reviews
  23. rating_item = "-1" # 10 Product_Rating
  24. addDate = "-1" # 11 Product_AddedDate
  25. BTC = "-1" # 12 Product_BTC_SellingPrice
  26. USD = "-1" # 13 Product_USD_SellingPrice
  27. EURO = "-1" # 14 Product_EURO_SellingPrice
  28. sold = "-1" # 15 Product_QuantitySold
  29. left = "-1" # 16 Product_QuantityLeft
  30. shipFrom = "-1" # 17 Product_ShippedFrom
  31. shipTo = "-1" # 18 Product_ShippedTo
  32. #finding the name of the product
  33. name_of_product = soup.find("h1", {"class": "product_title entry-title"}).text
  34. name = cleanString(name_of_product.strip())
  35. # finding the description of the product
  36. description_div = soup.find("div", {"class": "woocommerce-product-details__short-description"})
  37. if description_div is None:
  38. describe = "-1"
  39. else:
  40. describe = cleanString(description_div.text.strip())
  41. #find the category of the product
  42. name_of_category = soup.find("span", {"class": "posted_in"}).find("a").text
  43. category = cleanString(name_of_category.strip())
  44. #finding the name of the vendor
  45. name_of_vendor = soup.find("div", {"class": "dokan-vendor-name"}).find("h5").text
  46. vendor = cleanString(name_of_vendor)
  47. #finding the vendor's rating
  48. vendorRating = soup.find("div", {"class": "dokan-vendor-rating"}).find("p").text
  49. rating_vendor = cleanString(vendorRating)
  50. #everything else gets a -1 because they are not found
  51. # Populating the final variable (this should be a list with all fields scraped)
  52. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  53. BTC, USD, EURO, sold, left, shipFrom, shipTo)
  54. # Sending the results
  55. return row
  56. #parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  57. #stores info it needs in different lists, these lists are returned after being organized
  58. #@param: soup object looking at html page of listing page
  59. #return: 'row' that contains a variety of lists that each hold info on the listing page
  60. def nexus_listing_parser(soup):
  61. # Fields to be parsed
  62. nm = 0 # *Total_Products (Should be Integer)
  63. mktName = "Nexus" # 0 *Marketplace_Name
  64. vendor = [] # 1 *Vendor y
  65. rating_vendor = [] # 2 Vendor_Rating
  66. success = [] # 3 Vendor_Successful_Transactions
  67. name = [] # 4 *Product_Name y
  68. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  69. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  70. category = [] # 7 Product_Category y
  71. describe = [] # 8 Product_Description
  72. views = [] # 9 Product_Number_Of_Views
  73. reviews = [] # 10 Product_Number_Of_Reviews
  74. rating_item = [] # 11 Product_Rating
  75. addDate = [] # 12 Product_AddDate
  76. BTC = [] # 13 Product_BTC_SellingPrice
  77. USD = [] # 14 Product_USD_SellingPrice y
  78. EURO = [] # 15 Product_EURO_SellingPrice
  79. sold = [] # 16 Product_QuantitySold
  80. qLeft = [] # 17 Product_QuantityLeft
  81. shipFrom = [] # 18 Product_ShippedFrom
  82. shipTo = [] # 19 Product_ShippedTo
  83. href = [] # 20 Product_Links
  84. products_list = soup.find_all('li')
  85. nm = 0
  86. for product in products_list:
  87. try:
  88. # Finding the name of the product
  89. name_of_product = product.find("h2", {"class": "woocommerce-loop-product__title"}).find("a").text
  90. name_of_product_cleaned = cleanString(name_of_product.strip())
  91. # print(name_of_product_cleaned)
  92. name.append(name_of_product_cleaned)
  93. #finding the URL
  94. try:
  95. url = product.find("a", class_="woocommerce-loop-product__link").get('href')
  96. href.append(url)
  97. except AttributeError as e:
  98. print("I can't find the link")
  99. raise e
  100. #everything else appends a -1
  101. rating_vendor.append("-1")
  102. USD.append("-1")
  103. vendor.append("-1")
  104. success.append("-1")
  105. CVE.append("-1")
  106. MS.append("-1")
  107. category.append("-1")
  108. describe.append("-1")
  109. views.append("-1")
  110. reviews.append("-1")
  111. addDate.append("-1")
  112. BTC.append("-1")
  113. EURO.append("-1")
  114. sold.append("-1")
  115. qLeft.append("-1")
  116. shipFrom.append("-1")
  117. shipTo.append("-1")
  118. # print("Done! moving onto the next product!")
  119. # print(len(shipTo))
  120. nm += 1
  121. except AttributeError as e:
  122. print("I'm somewhere I don't belong. I'm going to leave")
  123. continue
  124. # Populate the final variable (this should be a list with all fields scraped)
  125. return organizeProducts(
  126. marketplace = "Nexus",
  127. nm = nm,
  128. vendor = vendor,
  129. rating_vendor = rating_vendor,
  130. success_vendor = success,
  131. nombre = name,
  132. CVE = CVE,
  133. MS = MS,
  134. category = category,
  135. describe = describe,
  136. views = views,
  137. reviews = reviews,
  138. rating_item = rating_item,
  139. addDate = addDate,
  140. BTC = BTC,
  141. USD = USD,
  142. EURO = EURO,
  143. sold = sold,
  144. qLeft = qLeft,
  145. shipFrom = shipFrom,
  146. shipTo = shipTo,
  147. href = href
  148. )
  149. #called by the crawler to get description links on a listing page
  150. #@param: beautifulsoup object that is using the correct html page (listing page)
  151. #return: list of description links from a listing page
  152. def nexus_links_parser(soup):
  153. # Returning all links that should be visited by the Crawler
  154. href = []
  155. # Using a shorter, but still unique, class name
  156. listing = soup.find_all("a", class_="woocommerce-loop-product__link")
  157. for a in listing:
  158. link = a.get('href')
  159. if link: # Checks if 'href' attribute is not None
  160. href.append(link)
  161. return href