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.

260 lines
9.8 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. __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 darkmatter_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. # 0 *Vendor_Name
  34. try:
  35. temp = soup.find('table', {'class', 'vtable'})
  36. temp = temp.findAll('tr')
  37. temp2 = temp[3].find('a').text
  38. vendor = cleanString(temp2.strip())
  39. except:
  40. temp = soup.find('table', {'class', 'vtable'})
  41. temp = temp.findAll('tr')
  42. temp2 = temp[4].find('a').text
  43. vendor = cleanString(temp2.strip())
  44. # product name
  45. name = soup.find('div', {'class', 'title-h2'}).text
  46. name = cleanString(name.strip())
  47. #product description
  48. temp = soup.find('pre', {'class', 'description'}).text
  49. temp = temp.replace('\n', ' ')
  50. describe = cleanString(temp.strip())
  51. # Finding Product Image
  52. #image = soup.find('div', {'class': 'woocommerce-product-gallery__image'}).find('img')
  53. #image = image.get('src')
  54. #product category
  55. try:
  56. temp = soup.find('table', {'class', 'vtable'})
  57. temp = temp.findAll('tr')
  58. temp2 = temp[4].find('th').text
  59. temp2 = cleanString(temp2)
  60. if (temp2 == "Category"):
  61. temp2 = temp[4].find('a').text
  62. category = cleanString(temp2.strip())
  63. except:
  64. temp = soup.find('table', {'class', 'vtable'})
  65. temp = temp.findAll('tr')
  66. temp2 = temp[5].find('th').text
  67. temp2 = cleanString(temp2.strip)
  68. if (temp2 == "Category"):
  69. temp2 = temp[5].find('a').text
  70. category = cleanString(temp2.strip())
  71. # usd
  72. temp = soup.find('table', {'class', 'vtable'})
  73. temp = temp.findAll('tr')
  74. temp2 = temp[1].find('td').text
  75. temp2 = temp2.replace(' USD', '')
  76. USD = cleanString(temp2)
  77. # 15 Product_QuantitySold
  78. temp = soup.find('table', {'class', 'vtable'})
  79. temp = temp.findAll('tr')
  80. temp2 = temp[5].find('th').text
  81. temp2 = cleanString(temp2)
  82. temp3 = temp[6].find('th').text
  83. temp3 = cleanString(temp3)
  84. if (temp2 == "Sold"):
  85. temp2 = temp[5].find('td').text
  86. sold = cleanString(temp2.strip())
  87. elif (temp3 == "Sold"):
  88. temp2 = temp[6].find('td').text
  89. sold = cleanString(temp2.strip())
  90. image = soup.find('td', {"class": "vtop"}).find('img').get('src')
  91. image = image.split('base64,')[-1]
  92. # Populating the final variable (this should be a list with all fields scraped)
  93. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  94. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
  95. # Sending the results
  96. return row
  97. #parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  98. #stores info it needs in different lists, these lists are returned after being organized
  99. #@param: soup object looking at html page of listing page
  100. #return: 'row' that contains a variety of lists that each hold info on the listing page
  101. def darkmatter_listing_parser(soup):
  102. # Fields to be parsed
  103. nm = 0 # *Total_Products (Should be Integer)
  104. mktName = "DarkMatter" # 0 *Marketplace_Name
  105. vendor = [] # 1 *Vendor y
  106. rating = [] # 2 Vendor_Rating
  107. success = [] # 3 Vendor_Successful_Transactions
  108. name = [] # 4 *Product_Name y
  109. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  110. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  111. category = [] # 7 Product_Category y
  112. describe = [] # 8 Product_Description
  113. views = [] # 9 Product_Number_Of_Views
  114. reviews = [] # 10 Product_Number_Of_Reviews
  115. rating_item = [] # 11 Product_Rating
  116. addDate = [] # 12 Product_AddDate
  117. BTC = [] # 13 Product_BTC_SellingPrice
  118. USD = [] # 14 Product_USD_SellingPrice y
  119. EURO = [] # 15 Product_EURO_SellingPrice
  120. sold = [] # 16 Product_QuantitySold
  121. qLeft =[] # 17 Product_QuantityLeft
  122. shipFrom = [] # 18 Product_ShippedFrom
  123. shipTo = [] # 19 Product_ShippedTo
  124. image = [] # 20 Product_Image
  125. image_vendor = [] # 21 Vendor_Image
  126. href = [] # 22 Product_Links
  127. names = soup.find('div', {"class": "content"}).findAll('td', {"class": "lefted", "colspan": "3"})
  128. left = soup.find('div', {"class": "content"}).findAll('table', {"class": "vtable"})
  129. right = soup.find('div', {"class": "content"}).findAll('td', {"class": "vtop centered"})
  130. images = soup.find('div', {"class": "content"}).findAll('td', {"class": "vcentered"})
  131. # vtop centered
  132. count = 0
  133. # Populating the Number of Products
  134. nm = len(names)
  135. for a in names:
  136. # product name
  137. temp = a.find('a').text
  138. if ("pcs x " in temp):
  139. index = temp.index("pcs x ")
  140. result = temp[index + len("pcs x "):]
  141. name.append(cleanString(result))
  142. elif("pks x " in temp):
  143. index = temp.index("pks x ")
  144. result = temp[index + len("pks x "):]
  145. name.append(cleanString(result))
  146. # Finding Product Image
  147. #product_image = a.find('img', {'class': 'attachment-woocommerce_thumbnail size-woocommerce_thumbnail'})
  148. #product_image = product_image.get('src')
  149. #image.append(product_image)
  150. CVE.append("-1")
  151. MS.append("-1")
  152. temp2 = left[count].findAll('tr')
  153. length_2 = len(temp2) - 1
  154. # category
  155. temp = temp2[1].find('td').text
  156. category.append(cleanString(temp.strip()))
  157. describe.append("-1")
  158. #escrow.append("-1")
  159. views.append("-1")
  160. reviews.append("-1")
  161. addDate.append("-1")
  162. #lastSeen.append("-1")
  163. BTC.append("-1")
  164. image_vendor.append("-1")
  165. # usd
  166. temp3 = right[count*2].find('span').text
  167. temp = temp3.replace(' USD', '')
  168. USD.append(cleanString(temp))
  169. EURO.append("-1")
  170. # 14 Product_QuantitySold
  171. temp3 = temp2[length_2].find('th').text
  172. temp3 = cleanString(temp3)
  173. if (temp3 == "Sold:"):
  174. temp = temp2[length_2].find('td').text
  175. sold.append(cleanString(temp.strip()))
  176. else:
  177. sold.append("-1")
  178. qLeft.append("-1")
  179. shipFrom.append("-1")
  180. # ship to
  181. temp3 = temp2[length_2].find('th').text
  182. temp3 = cleanString(temp3)
  183. if (temp3 == "Ship To:"):
  184. temp = temp2[length_2].find('td').text
  185. shipTo.append(cleanString(temp.strip()))
  186. else:
  187. shipTo.append("-1")
  188. # vendor
  189. temp = temp2[0].find('a').text
  190. vendor.append(cleanString(temp.strip()))
  191. # add product rating (stars)
  192. rating.append("-1")
  193. success.append("-1")
  194. temp = a.find('a').get('href')
  195. href.append(temp)
  196. image = images[count*2].find('img').get('src')
  197. image = image.split('base64,')[-1]
  198. count += 1
  199. rating_item.append("-1")
  200. # Populate the final variable (this should be a list with all fields scraped)
  201. return organizeProducts(mktName, nm, vendor, rating, success, name, CVE, MS, category, describe, views,
  202. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image, image_vendor)
  203. #called by the crawler to get description links on a listing page
  204. #@param: beautifulsoup object that is using the correct html page (listing page)
  205. #return: list of description links from a listing page
  206. def darkmatter_links_parser(soup):
  207. # Returning all links that should be visited by the Crawler
  208. href = []
  209. listing = soup.find('div', {"class": "content"}).findAll('td', {"class": "lefted", 'colspan': '3'})
  210. for a in listing:
  211. bae = a.find('a', href=True)
  212. link = bae['href']
  213. href.append(link)
  214. return href