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.

248 lines
9.5 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 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 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 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. # This is the method to parse the Description Pages (one page to each Product in the Listing Pages)
  7. def wethenorth_description_parser(soup):
  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. # Finding Product Name
  29. listDes = soup.find('div', {'class': "listDes"})
  30. name = listDes.find('h2').text
  31. name = name.replace('\n', ' ')
  32. name = name.replace(",", "")
  33. name = name.strip()
  34. # Finding Vendor
  35. vendor = listDes.find('b').text
  36. vendor = vendor.replace(",", "")
  37. vendor = vendor.replace("...", "")
  38. vendor = vendor.replace("-", "")
  39. vendor = vendor.strip()
  40. # Finding Vendor Rating
  41. rating = listDes.find('span',{'class':'levelSet'})
  42. rating = rating.text
  43. rating = rating.replace('\n', ' ')
  44. rating = rating.replace(",", "")
  45. rating = rating.strip()
  46. # Finding Successful Transactions
  47. success = listDes.find_all('p')[1]
  48. success = success.find('span').text
  49. success = success.split()
  50. success = success[0].strip()
  51. # Finding Prices - all prices in We The North are in CAD, I left the CAD in the resulting String so that it would show CAD for all prices
  52. padp = listDes.find('p',{'class':'padp'})
  53. USD = padp.find('span').text
  54. USD = USD.strip()
  55. # Finding Escrow - no escrow on WTN market
  56. shipping_info = listDes.find('tbody')
  57. if "Digital" not in shipping_info:
  58. shipping_info = shipping_info.find_all('tr')
  59. row1 = shipping_info[0].find_all('td')
  60. # Finding Shipment Information (Origin)
  61. shipFrom = row1[-1].text
  62. shipFrom=shipFrom.strip()
  63. if shipFrom=="":
  64. shipFrom="-1"
  65. row2 = shipping_info[1].find_all('td')
  66. # Finding Shipment Information (Destination)
  67. shipTo = row2[-1].text
  68. shipTo= shipTo.strip()
  69. if shipTo == "":
  70. shipTo = "-1"
  71. # Finding the Product description
  72. describe = soup.find("div",{'class':'tabcontent'})
  73. describe = describe.find('p').text
  74. describe = describe.replace("\n", " ")
  75. describe = describe.replace("\r", " ")
  76. describe = describe.strip()
  77. # cannot find any tag for these
  78. '''
  79. # Finding the Number of Product Reviews
  80. tag = soup.findAll(text=re.compile('Reviews'))
  81. for index in tag:
  82. reviews = index
  83. par = reviews.find('(')
  84. if par >=0:
  85. reviews = reviews.replace("Reviews (","")
  86. reviews = reviews.replace(")","")
  87. reviews = reviews.split(",")
  88. review = str(abs(int(reviews[0])) + abs(int(reviews[1])))
  89. else :
  90. review = "-1"
  91. '''
  92. # Searching for CVE and MS categories
  93. # no CVE or MS for WTN market
  94. # Populating the final variable (this should be a list with all fields scraped)
  95. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  96. BTC, USD, EURO, sold, left, shipFrom, shipTo)
  97. # Sending the results
  98. return row
  99. # This is the method to parse the Listing Pages
  100. def wethenorth_listing_parser(soup):
  101. # Fields to be parsed
  102. nm = 0 # *Total_Products (Should be Integer)
  103. mktName = "WeTheNorth" # 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)
  109. MS = [] # 6 Product_MS_Classification (Microsoft Security)
  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. right_content = soup.find('div', {"class": "right-content"})
  125. listing = right_content.findAll('div', {"class": "col-1search"})
  126. listing = listing[3:]
  127. # Populating the Number of Products
  128. nm = len(listing)
  129. for a in listing:
  130. bae = a.findAll('a', href=True)
  131. # Adding the url to the list of urls
  132. link = bae[0].get('href')
  133. link = cleanLink(link)
  134. href.append(link)
  135. # Finding the Vendor
  136. vendor_name = a.find('p', {'class': 'padp'})
  137. vendor_name = vendor_name.find('a').text
  138. vendor_name = vendor_name.replace(",", "")
  139. vendor_name = vendor_name.strip()
  140. vendor.append(vendor_name)
  141. # Finding the Product
  142. product = bae[0].text
  143. product = product.replace('\n', ' ')
  144. product = product.replace(",", "")
  145. product = product.strip()
  146. name.append(product)
  147. # Finding the Category
  148. category_name = a.find('p', {'class': 'padp'}).text
  149. first_dash = category_name.find('-')
  150. second_dash = category_name[first_dash+1:].find('-')
  151. category_name = category_name[first_dash+1:second_dash]
  152. category_name=category_name.strip()
  153. category.append(category_name)
  154. # Finding Views
  155. view_count = a.text
  156. view_count = view_count[view_count.find('Views:'): view_count.find('Sales:')]
  157. view_count = view_count.replace('Views:', ' ')
  158. view_count = view_count.replace('/', ' ')
  159. view_count = view_count.strip()
  160. views.append(view_count)
  161. # Finding success sales
  162. sold_count = a.text
  163. sold_count = sold_count[sold_count.find('Sales:'): sold_count.find('Short')]
  164. sold_count = sold_count.replace('Sales:', ' ')
  165. sold_count = sold_count.replace('/', ' ')
  166. sold_count = sold_count.strip()
  167. success.append(sold_count)
  168. # Searching for CVE and MS categories
  169. # no CVE or MS in WTN market
  170. cve = a.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  171. if not cve:
  172. cveValue="-1"
  173. else:
  174. cee = " "
  175. for idx in cve:
  176. cee += (idx)
  177. cee += " "
  178. cee = cee.replace(',', ' ')
  179. cee = cee.replace('\n', '')
  180. cveValue=cee
  181. CVE.append(cveValue)
  182. ms = a.findAll(text=re.compile('MS\d{2}-\d{3}'))
  183. if not ms:
  184. MSValue="-1"
  185. else:
  186. me = " "
  187. for im in ms:
  188. me += (im)
  189. me += " "
  190. me = me.replace(',', ' ')
  191. me = me.replace('\n', '')
  192. MSValue=me
  193. MS.append(MSValue)
  194. # Populate the final variable (this should be a list with all fields scraped)
  195. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  196. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href)
  197. def wethenorth_links_parser(soup):
  198. # Returning all links that should be visited by the Crawler
  199. href = []
  200. right_content = soup.find('div',{"class": "right-content"})
  201. listing = right_content.findAll('div', {"class": "col-1search"})
  202. #cut out the irrelevant products that are in blue, the first three products of each page usually unrelated
  203. listing = listing[3:]
  204. for a in listing:
  205. link = a.find('a')
  206. link = link['href']
  207. href.append(link)
  208. return href