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.

232 lines
8.0 KiB

  1. __author__ = 'Helium'
  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 lionmarketplace_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) dont worry about that much
  18. MS = "-1" # 6 Product_MS_Classification (Microsoft Security) dont worry about that much
  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. # vendor name
  32. temp = soup.find('div', {'class': 'btn-group'}).find('a').text
  33. vendor = (cleanString(temp.strip()))
  34. # table with info
  35. table = soup.find('table')
  36. rows = table.findAll('tr')
  37. # successful transaction
  38. success = "-1"
  39. # vendor rating 5
  40. rating_vendor = '-1'
  41. # product name
  42. temp = soup.find('div', {'class', 'row'}).find('h2').text
  43. name = (cleanString(temp.strip()))
  44. # product description
  45. temp = soup.find('div', {'class': "mt-4"}).find(text=True, recursive=False)
  46. describe = cleanString(temp.strip())
  47. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures) dont worry about that much
  48. MS = "-1" # 6 Product_MS_Classification (Microsoft Security) dont worry about that much
  49. # product category
  50. temp = rows[1].find('strong').text
  51. category = cleanString(temp.strip())
  52. # product number of views
  53. views = "-1"
  54. reviews = "-1" # 9 Product_Number_Of_Reviews
  55. rating_item = "-1" # 10 Product_Rating
  56. addDate = "-1" # 11 Product_AddedDate
  57. # BTC selling price box box-rounded mt-2
  58. BTC = "-1"
  59. # USD selling price
  60. temp = rows[2].find('strong').text
  61. if " $" in temp:
  62. temp = temp.replace(" $", "")
  63. elif "$" in temp:
  64. temp = temp.replace("$", "")
  65. USD = cleanString((temp.strip()))
  66. EURO = "-1" # 14 Product_EURO_SellingPrice
  67. # product sold
  68. if (len(rows) <= 5):
  69. temp = rows[4].find('td').text
  70. string = cleanString(temp)
  71. if (string == 'Left/Sold'):
  72. temp = rows[4].findAll('td')
  73. temp = temp[1].findAll('span')
  74. # left
  75. temp2 = temp[1].text
  76. temp3 = temp[1].text
  77. if(" items" in temp2):
  78. temp2 = temp2.replace(" items", "")
  79. if(" items" in temp3):
  80. temp3 = temp3.replace(" items", "")
  81. sold = (cleanString(temp2.strip()))
  82. left = cleanString(temp3.strip())
  83. else:
  84. sold = '-1'
  85. left = "-1"
  86. else:
  87. sold = '-1'
  88. left = "-1"
  89. shipFrom = "-1" # 17 Product_ShippedFrom
  90. shipTo = "-1" # 18 Product_ShippedTo
  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)
  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 lionmarketplace_listing_parser(soup):
  101. # Fields to be parsed
  102. nm = 0 # *Total_Products (Should be Integer)
  103. mktName = "LionMarketplace" # 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. href = [] # 20 Product_Links
  124. listings = soup.findAll('div', {"class": "col-md-4 my-md-0 my-2 col-12"})
  125. # Populating the Number of Products
  126. nm = len(listings)
  127. for listing in listings:
  128. a = listing.find('div', {"class": "card-body"})
  129. row = a.findAll('p')
  130. # vendor
  131. temp = row[3].text
  132. temp = temp.replace("Vendor:", "")
  133. vendor.append(cleanString(temp.strip()))
  134. # vendor rating
  135. rating_vendor.append("-1")
  136. # successful transactions CHECK AGAIN HERE
  137. success.append("-1")
  138. # product name
  139. temp = a.find('a').text
  140. name.append(cleanString(temp.strip()))
  141. CVE.append('-1')
  142. MS.append('-1')
  143. # product category
  144. temp = row[2].text
  145. temp = temp.replace("Category: ", "")
  146. category.append(cleanString(temp.strip()))
  147. describe.append('-1')
  148. # product views
  149. views.append("-1")
  150. reviews.append('-1') # 10 Product_Number_Of_Reviews
  151. rating_item.append('-1') # 11 Product_Rating
  152. addDate.append('-1') # 12 Product_AddDate
  153. # BTC
  154. BTC.append('-1')
  155. # USD
  156. temp = row[0].find('strong').text
  157. if ' $' in temp:
  158. temp = temp.replace(" $", "")
  159. USD.append(cleanString(temp.strip())) # 14 Product_USD_SellingPrice
  160. EURO.append("-1") # 15 Product_EURO_SellingPrice
  161. # product sold
  162. sold.append("-1")
  163. qLeft.append('-1') # 17 Product_QuantityLeft
  164. shipFrom.append('-1') # 18 Product_ShippedFrom
  165. shipTo.append('-1') # 19 Product_ShippedTo
  166. # href
  167. temp = a.find('a').get('href')
  168. href.append(temp)
  169. # Populate the final variable (this should be a list with all fields scraped)
  170. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  171. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href)
  172. #called by the crawler to get description links on a listing page
  173. #@param: beautifulsoup object that is using the correct html page (listing page)
  174. #return: list of description links from a listing page
  175. def lionmarketplace_links_parser(soup):
  176. # Returning all links that should be visited by the Crawler
  177. href = []
  178. listings = soup.findAll('div', {"class": "col-md-4 my-md-0 my-2 col-12"})
  179. for listing in listings:
  180. a = listing.find('div', {"class": "card-body"})
  181. bae = a.find('a', href=True)
  182. link = bae['href']
  183. href.append(link)
  184. return href