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.

168 lines
7.3 KiB

6 months 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. 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 darkroad_description_parser(soup):
  12. # Fields to be parsed
  13. vendor = "-1" # 0 *Vendor_Name n
  14. success = "-1" # 1 Vendor_Successful_Transactions n
  15. rating_vendor = "-1" # 2 Vendor_Rating n
  16. name = "-1" # 3 *Product_Name y
  17. describe = "-1" # 4 Product_Description y
  18. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  19. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  20. category = "-1" # 7 Product_Category y
  21. views = "-1" # 8 Product_Number_Of_Views n
  22. reviews = "-1" # 9 Product_Number_Of_Reviews y
  23. rating_item = "-1" # 10 Product_Rating y
  24. addDate = "-1" # 11 Product_AddedDate n
  25. BTC = "-1" # 12 Product_BTC_SellingPrice n
  26. USD = "-1" # 13 Product_USD_SellingPrice y
  27. EURO = "-1" # 14 Product_EURO_SellingPrice n
  28. sold = "-1" # 15 Product_QuantitySold n
  29. left = "-1" # 16 Product_QuantityLeft n
  30. shipFrom = "-1" # 17 Product_ShippedFrom n
  31. shipTo = "-1" # 18 Product_ShippedTo n
  32. image = "-1" # 19 Product_Image y
  33. vendor_image = "-1" # 20 Vendor_Image n
  34. # Finding Product Name
  35. name = soup.find('h1').text
  36. name = cleanString(name).strip()
  37. # Finding Product description
  38. describe_div = soup.find('div', {'class': "woocommerce-product-details__short-description"})
  39. describe = describe_div.get_text()
  40. describe = cleanString(describe).strip()
  41. # Finding category
  42. div_category = soup.find('div', {'class': "product_meta"})
  43. category = div_category.find('span', {"class": 'posted_in'}).get_text()
  44. category = cleanString(category).strip()
  45. # Finding Number of Reviews
  46. div_review_count = soup.find('a', {'class': "woocommerce-review-link"})
  47. reviews = div_review_count.find('span', {'class': 'count'}).text
  48. # Finding Review Rating
  49. div_rating_item = soup.find('div', {'class': "star-rating"})
  50. rating_item = div_rating_item.find('strong', {'class', "rating"}).text
  51. # Finding BTC and USD/GOLD
  52. div_price = soup.find('span', {'class': "woocommerce-Price-amount amount"})
  53. USD = div_price.text
  54. div_image = soup.find('div', {'class': "woocommerce-product-gallery woocommerce-product-gallery--with-images woocommerce-product-gallery--columns-4 images"})
  55. div_image = div_image.find('img')
  56. image = div_image.get('src').split('base64,')[-1]
  57. # Populating the final variable (this should be a list with all fields scraped)
  58. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  59. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
  60. # Sending the results
  61. return row
  62. # parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  63. # stores info it needs in different lists, these lists are returned after being organized
  64. # @param: soup object looking at html page of listing page
  65. # return: 'row' that contains a variety of lists that each hold info on the listing page
  66. def darkroad_listing_parser(soup):
  67. # Fields to be parsed
  68. nm = 0 # *Total_Products (Should be Integer)
  69. mktName = "DarkRoad" # 0 *Marketplace_Name y
  70. vendor = [] # 1 *Vendor n
  71. rating_vendor = [] # 2 Vendor_Rating n
  72. success = [] # 3 Vendor_Successful_Transactions n
  73. name = [] # 4 *Product_Name y
  74. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures) dont worry about this
  75. MS = [] # 6 Product_MS_Classification (Microsoft Security) dont worry about this
  76. category = [] # 7 Product_Category y
  77. describe = [] # 8 Product_Description n
  78. views = [] # 9 Product_Number_Of_Views n
  79. reviews = [] # 10 Product_Number_Of_Reviews n
  80. rating_item = [] # 11 Product_Rating y
  81. addDate = [] # 12 Product_AddDate n
  82. BTC = [] # 13 Product_BTC_SellingPrice n
  83. USD = [] # 14 Product_USD_SellingPrice y
  84. EURO = [] # 15 Product_EURO_SellingPrice n
  85. sold = [] # 16 Product_QuantitySold n
  86. qLeft = [] # 17 Product_QuantityLeft n
  87. shipFrom = [] # 18 Product_ShippedFrom n
  88. shipTo = [] # 19 Product_ShippedTo n
  89. image = [] # 20 Product_Image y
  90. image_vendor = [] # 21 Vendor_Image n
  91. href = [] # 22 Product_Links y
  92. listings = soup.findAll('a', {"class": "woocommerce-LoopProduct-link woocommerce-loop-product__link"})
  93. # Populating the Number of Products
  94. nm = len(listings)
  95. for listing in listings:
  96. # Finding the product name
  97. product_name = listing.find('h2', {"class": "woocommerce-loop-product__title"}).text
  98. product_name = cleanString(product_name).strip()
  99. name.append(product_name)
  100. # Finding the category
  101. category_name = soup.find('h1', {"class": "page-title"}).get_text()
  102. category_name = cleanString(category_name).strip()
  103. category.append(category_name)
  104. # Finding the BTC and USD/GOLD
  105. USD_price = listing.find('span', {"class": "woocommerce-Price-amount amount"}).get_text()
  106. USD_price = cleanString(USD_price).strip()
  107. USD.append(USD_price)
  108. # Finding the item rating
  109. rating_div = listing.find('div', {"class": "star-rating"})
  110. rating = rating_div.find('strong').text
  111. rating = cleanString(rating).strip()
  112. rating_item.append(rating)
  113. # Finding product image
  114. product_image = listing.find('img', {"class": "attachment-woocommerce_thumbnail size-woocommerce_thumbnail"})
  115. product_image = product_image.get('src').split('base64,')[-1]
  116. image.append(product_image)
  117. # Finding the hrefs
  118. description_link = listing["href"]
  119. href.append(description_link)
  120. # Populate the final variable (this should be a list with all fields scraped)
  121. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  122. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image,
  123. image_vendor)
  124. # called by the crawler to get description links on a listing page
  125. # @param: beautifulsoup object that is using the correct html page (listing page)
  126. # return: list of description links from a listing page
  127. def darkroad_links_parser(soup):
  128. href = []
  129. listings = soup.findAll('li')
  130. for listing in listings:
  131. # Adding the url to the list of urls
  132. try:
  133. description_link = listing.find('a', class_="woocommerce-LoopProduct-link woocommerce-loop-product__link")['href']
  134. href.append(description_link)
  135. except:
  136. pass
  137. return href