__author__ = 'DarkWeb'
|
|
|
|
# Here, we are importing the auxiliary functions to clean or convert data
|
|
from MarketPlaces.Utilities.utilities import *
|
|
|
|
def darkdock_description_parser(soup):
|
|
"""Parses the description pages of a DarkDock marketplace.
|
|
|
|
It takes a BeautifulSoup object that represents the HTML page of a description page, and
|
|
extracts various information such as vendor name, product name, etc.
|
|
|
|
Args:
|
|
soup: A BeautifulSoup object that represents the HTML page of a description page.
|
|
|
|
Returns:
|
|
The row of a description item as a tuple containing the information fields extracted from the description page.
|
|
"""
|
|
vendor = "-1" # 0 Vendor_Name
|
|
success = "-1" # 1 Vendor_Successful_Transactions
|
|
rating_vendor = "-1" # 2 Vendor_Rating
|
|
name = "-1" # 3 Product_Name
|
|
describe = "-1" # 4 Product_Description
|
|
CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
|
|
MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
|
|
category = "-1" # 7 Product_Category
|
|
views = "-1" # 8 Product_Number_Of_Views
|
|
reviews = "-1" # 9 Product_Number_Of_Reviews
|
|
rating_item = "-1" # 10 Product_Rating
|
|
addDate = "-1" # 11 Product_AddedDate
|
|
BTC = "-1" # 12 Product_BTC_SellingPrice
|
|
USD = "-1" # 13 Product_USD_SellingPrice
|
|
EURO = "-1" # 14 Product_EURO_SellingPrice
|
|
sold = "-1" # 15 Product_QuantitySold
|
|
left = "-1" # 16 Product_QuantityLeft
|
|
shipFrom = "-1" # 17 Product_ShippedFrom
|
|
shipTo = "-1" # 18 Product_ShippedTo
|
|
image = "-1" # 19 Product_Image
|
|
vendor_image = "-1" # 20 Vendor_Image
|
|
|
|
# Finding Vendor
|
|
vendor = soup.select_one('table tr:nth-of-type(2) td:nth-of-type(3) a u').text
|
|
vendor = cleanString(vendor)
|
|
vendor = vendor.strip()
|
|
|
|
# Finding Product Name
|
|
headings = soup.find('div', {'class': 'main'}).find_all('div', {'class': 'heading'})
|
|
name = headings[0].text
|
|
name = cleanString(name)
|
|
name = name.strip()
|
|
|
|
# Finding the Product description
|
|
describe = soup.find('div', {'class': 'tab1'}).text
|
|
describe = cleanString(describe)
|
|
describe = describe.strip()
|
|
|
|
# Finding the Product category
|
|
category = soup.select_one('table tr:nth-of-type(6) td:nth-of-type(3)').text
|
|
category = cleanString(category)
|
|
category = category.strip()
|
|
|
|
# Finding Number of Product Reviews
|
|
reviews = headings[1].text
|
|
match = re.search(r'\((\d+)\)', reviews).group(1)
|
|
reviews = cleanNumbers(reviews)
|
|
reviews = reviews.strip()
|
|
|
|
# Finding Prices
|
|
USD = soup.select_one('table tr:nth-of-type(1) td:nth-of-type(3)').text
|
|
USD = cleanNumbers(USD)
|
|
USD = USD.strip()
|
|
|
|
# Finding the Product Quantity Available
|
|
left = soup.select_one('table tr:nth-of-type(7) td:nth-of-type(3)').text
|
|
left = cleanNumbers(left)
|
|
left = left.strip()
|
|
|
|
# Finding Product Shipped From
|
|
shipFrom = soup.select_one('table tr:nth-of-type(3) td:nth-of-type(3)').text
|
|
shipFrom = cleanString(shipFrom)
|
|
shipFrom = shipFrom.strip()
|
|
|
|
# Finding Product Shipped To
|
|
shipTo = soup.select_one('table tr:nth-of-type(5) td:nth-of-type(3)').text
|
|
shipTo = cleanString(shipTo)
|
|
shipTo = shipTo.strip()
|
|
|
|
# Finding Product Image
|
|
image = soup.find('img', {'class': 'bigthumbnail'}).get('src')
|
|
image = image.split('base64,')[-1]
|
|
|
|
# Populating the final variable (this should be a list with all fields scraped)
|
|
row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
|
|
BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
|
|
|
|
# Sending the results
|
|
return row
|
|
|
|
def darkdock_listing_parser(soup):
|
|
"""Parses the listing pages of a DarkDock marketplace.
|
|
|
|
It takes a BeautifulSoup object that represents the HTML page of a listing page,
|
|
and extracts various information such as vendor name, product name, etc. It then
|
|
removes and cleans the extracted information by passing it to the organizeProducts
|
|
function.
|
|
|
|
Args:
|
|
soup: A BeautifulSoup object that represents the HTML page of a listing page.
|
|
|
|
Returns:
|
|
The row of a description item as a tuple containing the information fields extracted from the listing page.
|
|
"""
|
|
# Fields to be parsed
|
|
nm = 0 # Total_Products (Should be Integer)
|
|
mktName = "DarkDock" # 0 Marketplace_Name
|
|
vendor = [] # 1 Vendor
|
|
rating_vendor = [] # 2 Vendor_Rating
|
|
success = [] # 3 Vendor_Successful_Transactions
|
|
name = [] # 4 Product_Name
|
|
CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures) dont worry about this
|
|
MS = [] # 6 Product_MS_Classification (Microsoft Security) dont worry about this
|
|
category = [] # 7 Product_Category
|
|
describe = [] # 8 Product_Description
|
|
views = [] # 9 Product_Number_Of_Views
|
|
reviews = [] # 10 Product_Number_Of_Reviews
|
|
rating_item = [] # 11 Product_Rating
|
|
addDate = [] # 12 Product_AddDate
|
|
BTC = [] # 13 Product_BTC_SellingPrice
|
|
USD = [] # 14 Product_USD_SellingPrice
|
|
EURO = [] # 15 Product_EURO_SellingPrice
|
|
sold = [] # 16 Product_QuantitySold
|
|
qLeft = [] # 17 Product_QuantityLeft
|
|
shipFrom = [] # 18 Product_ShippedFrom
|
|
shipTo = [] # 19 Product_ShippedTo
|
|
image = [] # 20 Product_Image
|
|
image_vendor = [] # 21 Vendor_Image
|
|
href = [] # 22 Product_Links
|
|
|
|
listings = soup.findAll('div', {'class': 'item'})
|
|
|
|
# Populating the Number of Products
|
|
nm = len(listings)
|
|
cat = soup.find('div', {'class': 'heading'}).text
|
|
cat = cleanString(cat)
|
|
cat = cat.strip()
|
|
|
|
for listing in listings:
|
|
# Finding the Vendor
|
|
vendor_name = listing.find('div', {'class': 'seller'}).text
|
|
vendor.append(vendor_name)
|
|
|
|
# Finding the Product
|
|
product = listing.find('div', {'class': 'title'}).text
|
|
product = cleanString(product)
|
|
product = product.strip()
|
|
name.append(product)
|
|
|
|
# Finding the Category
|
|
category.append(cat)
|
|
|
|
# Finding description
|
|
description = listing.find('div', {'class': 'description'}).text
|
|
description = cleanString(description)
|
|
description = description.strip()
|
|
describe.append(description)
|
|
|
|
# Finding product views
|
|
num_view = listing.select_one('.stats table tr:nth-of-type(3) td:nth-of-type(1)').text
|
|
num_view = cleanNumbers(num_view)
|
|
num_view = num_view.strip()
|
|
views.append(num_view)
|
|
|
|
# Finding product reviews
|
|
num_reviews = listing.select_one('.stats table tr:nth-of-type(3) td:nth-of-type(3)').text
|
|
num_reviews = cleanNumbers(num_reviews)
|
|
num_reviews = num_reviews.strip()
|
|
reviews.append(num_reviews)
|
|
|
|
# Finding product rating based on width style
|
|
rating = listing.find('div', {'class': 'stars2'}).get('style')
|
|
rating = re.findall(r"\d+\.\d+|\d+", rating)[0]
|
|
rating = cleanNumbers(rating)
|
|
rating = rating.strip()
|
|
rating_item.append(rating)
|
|
|
|
# Finding Prices
|
|
price = listing.find('div', {'class': 'price'}).text
|
|
price = price.strip()
|
|
USD.append(price)
|
|
|
|
# Finding number of times product is sold
|
|
num_sold = listing.select_one('.stats table tr:nth-of-type(3) td:nth-of-type(2)').text
|
|
num_sold = cleanNumbers(num_sold)
|
|
num_sold = num_sold.strip()
|
|
sold.append(num_sold)
|
|
|
|
# Finding shipping locations
|
|
shipping = listing.find('div',{'class': 'shipping'}).text
|
|
shippedFrom, shippedTo = cleanString(shipping).split(' > ')
|
|
shipTo.append(shippedTo)
|
|
shipFrom.append(shippedFrom)
|
|
|
|
# Adding the url to the list of urls
|
|
link = listing.find('a', recursive=False).get('href')
|
|
href.append(link)
|
|
|
|
image_vendor.append("-1")
|
|
|
|
return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
|
|
reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image, image_vendor)
|
|
|
|
def darkdock_links_parser(soup):
|
|
"""Returns a list of description links from a listing page.
|
|
|
|
It takes a BeautifulSoup object that represents the HTML page of a listing page, and
|
|
extracts all the description links from the page.
|
|
|
|
Args:
|
|
soup: A BeautifulSoup object that represents the HTML page of a listing page.
|
|
|
|
Returns:
|
|
A list of description links from a listing page.
|
|
"""
|
|
|
|
# Returning all links that should be visited by the Crawler
|
|
|
|
href = []
|
|
listing = soup.find_all('a', href=lambda href: href and '/product/' in href)
|
|
|
|
for a in listing:
|
|
href.append(a['href'])
|
|
|
|
return href
|