|
|
- __author__ = 'DarkWeb'
-
-
- # Here, we are importing the auxiliary functions to clean or convert data
- from MarketPlaces.Utilities.utilities import *
-
- # Here, we are importing BeautifulSoup to search through the HTML tree
- from bs4 import BeautifulSoup
- import re
-
-
- # parses description pages, so takes html pages of description pages using soup object, and parses it for info it needs
- # stores info it needs in different lists, these lists are returned after being organized
- # @param: soup object looking at html page of description page
- # return: 'row' that contains a variety of lists that each hold info on the description page
- def darkroad_description_parser(soup):
- # Fields to be parsed
-
- vendor = "-1" # 0 *Vendor_Name n
- success = "-1" # 1 Vendor_Successful_Transactions n
- rating_vendor = "-1" # 2 Vendor_Rating n
- name = "-1" # 3 *Product_Name y
- describe = "-1" # 4 Product_Description y
- CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
- MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
- category = "-1" # 7 Product_Category y
- views = "-1" # 8 Product_Number_Of_Views n
- reviews = "-1" # 9 Product_Number_Of_Reviews y
- rating_item = "-1" # 10 Product_Rating y
- addDate = "-1" # 11 Product_AddedDate n
- BTC = "-1" # 12 Product_BTC_SellingPrice n
- USD = "-1" # 13 Product_USD_SellingPrice y
- EURO = "-1" # 14 Product_EURO_SellingPrice n
- sold = "-1" # 15 Product_QuantitySold n
- left = "-1" # 16 Product_QuantityLeft n
- shipFrom = "-1" # 17 Product_ShippedFrom n
- shipTo = "-1" # 18 Product_ShippedTo n
- image = "-1" # 19 Product_Image y
- vendor_image = "-1" # 20 Vendor_Image n
-
- # Finding Product Name
- name = soup.find('h1').text
- name = cleanString(name).strip()
-
- # Finding Product description
- describe_div = soup.find('div', {'class': "woocommerce-product-details__short-description"})
- describe = describe_div.get_text()
- describe = cleanString(describe).strip()
-
- # Finding category
- div_category = soup.find('div', {'class': "product_meta"})
- category = div_category.find('span', {"class": 'posted_in'}).get_text()
- category = cleanString(category).strip()
-
- # Finding Number of Reviews
- div_review_count = soup.find('a', {'class': "woocommerce-review-link"})
- reviews = div_review_count.find('span', {'class': 'count'}).text
-
- # Finding Review Rating
- div_rating_item = soup.find('div', {'class': "star-rating"})
- rating_item = div_rating_item.find('strong', {'class', "rating"}).text
-
- # Finding BTC and USD/GOLD
- div_price = soup.find('span', {'class': "woocommerce-Price-amount amount"})
- USD = div_price.text
-
- div_image = soup.find('div', {'class': "woocommerce-product-gallery woocommerce-product-gallery--with-images woocommerce-product-gallery--columns-4 images"})
- div_image = div_image.find('img')
- image = div_image.get('src').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
-
-
- # parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
- # stores info it needs in different lists, these lists are returned after being organized
- # @param: soup object looking at html page of listing page
- # return: 'row' that contains a variety of lists that each hold info on the listing page
- def darkroad_listing_parser(soup):
- # Fields to be parsed
- nm = 0 # *Total_Products (Should be Integer)
- mktName = "DarkRoad" # 0 *Marketplace_Name y
- vendor = [] # 1 *Vendor n
- rating_vendor = [] # 2 Vendor_Rating n
- success = [] # 3 Vendor_Successful_Transactions n
- name = [] # 4 *Product_Name y
- 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 y
- describe = [] # 8 Product_Description n
- views = [] # 9 Product_Number_Of_Views n
- reviews = [] # 10 Product_Number_Of_Reviews n
- rating_item = [] # 11 Product_Rating y
- addDate = [] # 12 Product_AddDate n
- BTC = [] # 13 Product_BTC_SellingPrice n
- USD = [] # 14 Product_USD_SellingPrice y
- EURO = [] # 15 Product_EURO_SellingPrice n
- sold = [] # 16 Product_QuantitySold n
- qLeft = [] # 17 Product_QuantityLeft n
- shipFrom = [] # 18 Product_ShippedFrom n
- shipTo = [] # 19 Product_ShippedTo n
- image = [] # 20 Product_Image y
- image_vendor = [] # 21 Vendor_Image n
- href = [] # 22 Product_Links y
-
- listings = soup.findAll('a', {"class": "woocommerce-LoopProduct-link woocommerce-loop-product__link"})
-
- # Populating the Number of Products
- nm = len(listings)
-
- for listing in listings:
- # Finding the product name
- product_name = listing.find('h2', {"class": "woocommerce-loop-product__title"}).text
- product_name = cleanString(product_name).strip()
- name.append(product_name)
-
- # Finding the category
- category_name = soup.find('h1', {"class": "page-title"}).get_text()
- category_name = cleanString(category_name).strip()
- category.append(category_name)
-
- # Finding the BTC and USD/GOLD
- USD_price = listing.find('span', {"class": "woocommerce-Price-amount amount"}).get_text()
- USD_price = cleanString(USD_price).strip()
- USD.append(USD_price)
-
- # Finding the item rating
- rating_div = listing.find('div', {"class": "star-rating"})
- rating = rating_div.find('strong').text
- rating = cleanString(rating).strip()
- rating_item.append(rating)
-
- # Finding product image
- product_image = listing.find('img', {"class": "attachment-woocommerce_thumbnail size-woocommerce_thumbnail"})
- product_image = product_image.get('src').split('base64,')[-1]
- image.append(product_image)
-
- # Finding the hrefs
- description_link = listing["href"]
- href.append(description_link)
- # Populate the final variable (this should be a list with all fields scraped)
- 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)
-
-
- # called by the crawler to get description links on a listing page
- # @param: beautifulsoup object that is using the correct html page (listing page)
- # return: list of description links from a listing page
-
- def darkroad_links_parser(soup):
-
- href = []
- listings = soup.findAll('li')
-
- for listing in listings:
- # Adding the url to the list of urls
- try:
- description_link = listing.find('a', class_="woocommerce-LoopProduct-link woocommerce-loop-product__link")['href']
- href.append(description_link)
- except:
- pass
-
- return href
|