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.

180 lines
7.6 KiB

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. #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 torbay_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. # Finding Product Name
  34. try:
  35. product_name = soup.find('div', {'class': 'product-information'}).find('h1').text
  36. name = cleanString(product_name.strip())
  37. except:
  38. product_name = soup.find('div', {'class': 'profile-info'}).find('h2').text
  39. name = cleanString(product_name.strip())
  40. # Finding Vendor FIx
  41. vendor_name = soup.find('div', {"class": "profile-info"}).find('h2').text
  42. vendor = cleanString(vendor_name.strip())
  43. # Finding Vendor Image
  44. vendor_image = soup.find('div', {'class': 'avatar'}).find('img')
  45. vendor_image = vendor_image.get('src')
  46. vendor_image = vendor_image.split('base64,')[-1]
  47. # Finding Prices
  48. USD = soup.find('div', {'class': "total-price"}).find('span').text.strip()
  49. # Finding the Product Category
  50. cat = soup.find('div', {'class': "profile-info"}).find('p').text
  51. category = cleanString(cat.strip())
  52. # Finding the Product description
  53. try:
  54. describe = soup.find('div', {'class': "info"}).find('p').text
  55. if "\n" in describe:
  56. describe = describe.replace("\n", " ")
  57. describe = describe.replace("\r", " ")
  58. describe = cleanString(describe.strip())
  59. except:
  60. # print("product desc")
  61. describe = soup.find('div', {'class': 'info'}).text
  62. describe = cleanString(describe.strip())
  63. # Finding Product Image
  64. image = soup.find('div', {'class': 'image text-center'}).find('img')
  65. image = image.get('src')
  66. image = image.split('base64,')[-1]
  67. # Populating the final variable (this should be a list with all fields scraped)
  68. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  69. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
  70. # Sending the results
  71. return row
  72. #parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  73. #stores info it needs in different lists, these lists are returned after being organized
  74. #@param: soup object looking at html page of listing page
  75. #return: 'row' that contains a variety of lists that each hold info on the listing page
  76. def torbay_listing_parser(soup):
  77. # Fields to be parsed
  78. nm = 0 # *Total_Products (Should be Integer)
  79. mktName = "TorBay" # 0 *Marketplace_Name
  80. vendor = [] # 1 *Vendor y
  81. rating_vendor = [] # 2 Vendor_Rating
  82. success = [] # 3 Vendor_Successful_Transactions
  83. name = [] # 4 *Product_Name y
  84. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  85. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  86. category = [] # 7 Product_Category y
  87. describe = [] # 8 Product_Description
  88. views = [] # 9 Product_Number_Of_Views
  89. reviews = [] # 10 Product_Number_Of_Reviews
  90. rating_item = [] # 11 Product_Rating
  91. addDate = [] # 12 Product_AddDate
  92. BTC = [] # 13 Product_BTC_SellingPrice
  93. USD = [] # 14 Product_USD_SellingPrice y
  94. EURO = [] # 15 Product_EURO_SellingPrice
  95. sold = [] # 16 Product_QuantitySold
  96. qLeft =[] # 17 Product_QuantityLeft
  97. shipFrom = [] # 18 Product_ShippedFrom
  98. shipTo = [] # 19 Product_ShippedTo
  99. image = [] # 20 Product_Image
  100. image_vendor = [] # 21 Vendor_Image
  101. href = [] # 22 Product_Links
  102. listing = soup.findAll('div', {"class": "product-card"})
  103. # Populating the Number of Products
  104. nm = len(listing)
  105. for a in listing:
  106. product_name = a.find('p', {'class': 'name'}).text
  107. name.append(cleanString(product_name.strip()))
  108. # Finding Product Image
  109. image.append("-1")
  110. prod = a.find('p', {'class': 'price'}).text # price
  111. USD.append(cleanString(prod.strip()))
  112. ven = a.find('div', {'class': 'pc-footer'}).find('div').find('a').text # pc-footer
  113. vendor.append(cleanString(ven.strip()))
  114. # print(ven)
  115. # Finding Vendor Image
  116. image_vendor.append("-1")
  117. h = a.find('p', {'class': 'name'}).find('a').get('href')
  118. href.append(h)
  119. CVE.append("-1")
  120. MS.append("-1")
  121. rating_vendor.append("-1")
  122. success.append("-1")
  123. describe.append("-1")
  124. views.append("-1")
  125. reviews.append("-1")
  126. rating_item.append("-1")
  127. addDate.append("-1")
  128. BTC.append("-1")
  129. EURO.append("-1")
  130. sold.append("-1")
  131. qLeft.append("-1")
  132. shipFrom.append("-1")
  133. shipTo.append("-1")
  134. category.append("Hacking")
  135. # Populate the final variable (this should be a list with all fields scraped)
  136. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  137. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image, image_vendor)
  138. #called by the crawler to get description links on a listing page
  139. #@param: beautifulsoup object that is using the correct html page (listing page)
  140. #return: list of description links from a listing page
  141. def torbay_links_parser(soup):
  142. # Returning all links that should be visited by the Crawler
  143. href = []
  144. listing = soup.find('section', {"id": "content"}).findAll('div', {"class": "product-card"})
  145. for a in listing:
  146. bae = a.find('div', {"class": "pc-footer"}).find('a', {"class": "btn btn-primary"}, href=True)
  147. link = bae['href']
  148. href.append(link)
  149. return href