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.

161 lines
7.0 KiB

  1. __author__ = 'DarkWeb'
  2. # Here, we are importing the auxiliary functions to clean or convert data
  3. from typing import List, Tuple
  4. from MarketPlaces.Utilities.utilities import *
  5. # Here, we are importing BeautifulSoup to search through the HTML tree
  6. from bs4 import BeautifulSoup, ResultSet, Tag
  7. def thiefWorld_description_parser(soup: BeautifulSoup) -> Tuple:
  8. # Fields to be parsed
  9. vendor = "-1" # 0 *Vendor_Name
  10. success = "-1" # 1 Vendor_Successful_Transactions
  11. rating_vendor = "-1" # 2 Vendor_Rating
  12. name = "-1" # 3 *Product_Name
  13. describe = "-1" # 4 Product_Description
  14. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  15. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  16. category = "-1" # 7 Product_Category
  17. views = "-1" # 8 Product_Number_Of_Views
  18. reviews = "-1" # 9 Product_Number_Of_Reviews
  19. rating_item = "-1" # 10 Product_Rating
  20. addDate = "-1" # 11 Product_AddedDate
  21. BTC = "-1" # 12 Product_BTC_SellingPrice
  22. USD = "-1" # 13 Product_USD_SellingPrice
  23. EURO = "-1" # 14 Product_EURO_SellingPrice
  24. sold = "-1" # 15 Product_QuantitySold
  25. left = "-1" # 16 Product_QuantityLeft
  26. shipFrom = "-1" # 17 Product_ShippedFrom
  27. shipTo = "-1" # 18 Product_ShippedTo
  28. name = soup.find("h1", {'class': 'title'}).text
  29. name = cleanString(name.strip())
  30. describe = soup.find('div', {'id': 'descriptionContent'}).text
  31. describe = cleanString(describe.strip())
  32. commentListTag: Tag = soup.find('ul', {'class': 'comment_list scrollbar'})
  33. commentList = commentListTag.find_all('li')
  34. review = str(len(commentList))
  35. citySelection: str = soup.find('ul', {'class': 'meta text-muted i_location'}).text
  36. shipFrom = cleanString(citySelection.strip())
  37. vendor = soup.find('h1', {'class': 'title over'}).text
  38. vendor = cleanString(vendor.strip())
  39. usdTag: Tag = soup.find('div', {'class': 'product_price__big'}).find('span')
  40. usdText = usdTag.text.strip('/')[0]
  41. # usdText format: "<value> USD " (i.e., "70 000 USD ")
  42. USD = cleanString(usdText.replace("USD", "").strip())
  43. ratingDiv = soup.find('div', {'class': 'rating_star'})
  44. rating_vendor = ratingDiv.get('title').strip(' ')[1]
  45. # Populating the final variable (this should be a list with all fields scraped)
  46. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  47. BTC, USD, EURO, sold, left, shipFrom, shipTo)
  48. # Sending the results
  49. return row
  50. def thiefWorld_listing_parser(soup: BeautifulSoup):
  51. # Fields to be parsed
  52. nm = 0 # Total_Products (Should be Integer)
  53. mktName = "ThiefWorld" # 0 Marketplace_Name
  54. vendor = [] # 1 *Vendor y
  55. rating_vendor = [] # 2 Vendor_Rating
  56. success = [] # 3 Vendor_Successful_Transactions
  57. name = [] # 4 *Product_Name y
  58. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  59. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  60. category = [] # 7 Product_Category y
  61. describe = [] # 8 Product_Description
  62. views = [] # 9 Product_Number_Of_Views
  63. reviews = [] # 10 Product_Number_Of_Reviews
  64. rating_item = [] # 11 Product_Rating
  65. addDate = [] # 12 Product_AddDate
  66. BTC = [] # 13 Product_BTC_SellingPrice
  67. USD = [] # 14 Product_USD_SellingPrice y
  68. EURO = [] # 15 Product_EURO_SellingPrice
  69. sold = [] # 16 Product_QuantitySold
  70. qLeft =[] # 17 Product_QuantityLeft
  71. shipFrom = [] # 18 Product_ShippedFrom
  72. shipTo = [] # 19 Product_ShippedTo
  73. href = [] # 20 Product_Links
  74. productList: ResultSet[Tag] = soup.find_all('div', {'class': 'catalog_item'})
  75. nm = len(productList)
  76. for product in productList:
  77. productTitle: Tag = product.find('div', {'class': 'title'}).find('a')
  78. productName = cleanString(productTitle.text.strip())
  79. name.append(productName)
  80. productHref = productTitle.get('href')
  81. href.append(productHref)
  82. CVE.append('-1')
  83. MS.append('-1')
  84. category.append('-1')
  85. productDescription = product.find('div', {'class': 'text'}).text
  86. productDescription = cleanString(productDescription.strip())
  87. describe.append(productDescription)
  88. views.append('-1')
  89. reviews.append('-1')
  90. addDate.append('-1')
  91. BTC.append('-1')
  92. priceText = product.find('span', {'class': 'price'}).find('span').text
  93. priceText = priceText.split('USD')[0]
  94. priceText = cleanString(priceText.strip())
  95. USD.append(priceText)
  96. EURO.append('-1')
  97. sold.append('-1')
  98. qLeft.append('-1')
  99. shipFrom.append('-1')
  100. shipTo.append('-1')
  101. productVendor = product.find('div', {'class': 'market over'}).find('a').text
  102. productVendor = cleanString(productVendor.strip())
  103. vendor.append(productVendor)
  104. rating_vendor.append('-1')
  105. rating_item.append('-1')
  106. success.append('-1')
  107. # Populate the final variable (this should be a list with all fields scraped)
  108. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  109. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href)
  110. #called by the crawler to get description links on a listing page
  111. #@param: beautifulsoup object that is using the correct html page (listing page)
  112. #return: list of description links from a listing page
  113. def thiefworld_links_parser(soup):
  114. # Returning all links that should be visited by the Crawler
  115. href = []
  116. listing = soup.find('div', {"class": "row tile__list tileitems_filter pad15 tileproduct__list"}).findAll('div', {"class": "desc"})
  117. for a in listing:
  118. bae = a.find('div', {"class": "title"}).find('a', href=True)
  119. link = bae['href']
  120. href.append(link)
  121. return href