|
@ -1,4 +1,4 @@ |
|
|
__author__ = 'Helium' |
|
|
|
|
|
|
|
|
__author__ = 'DarkWeb' |
|
|
|
|
|
|
|
|
''' |
|
|
''' |
|
|
DarkBazar Marketplace Crawler (Selenium) |
|
|
DarkBazar Marketplace Crawler (Selenium) |
|
@ -10,6 +10,7 @@ from selenium.webdriver.firefox.firefox_profile import FirefoxProfile |
|
|
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary |
|
|
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary |
|
|
from selenium.webdriver.firefox.service import Service |
|
|
from selenium.webdriver.firefox.service import Service |
|
|
from selenium.webdriver.support.ui import WebDriverWait |
|
|
from selenium.webdriver.support.ui import WebDriverWait |
|
|
|
|
|
from selenium.webdriver.support.ui import Select |
|
|
from selenium.webdriver.support import expected_conditions as EC |
|
|
from selenium.webdriver.support import expected_conditions as EC |
|
|
from selenium.webdriver.common.by import By |
|
|
from selenium.webdriver.common.by import By |
|
|
|
|
|
|
|
@ -25,99 +26,11 @@ from MarketPlaces.DarkBazar.parser import darkbazar_links_parser |
|
|
from MarketPlaces.Utilities.utilities import cleanHTML |
|
|
from MarketPlaces.Utilities.utilities import cleanHTML |
|
|
|
|
|
|
|
|
counter = 1 |
|
|
counter = 1 |
|
|
baseURL = 'http://jw5e5sdywqupaqgtt43uq5ysfqpd2vzefl65s2fcjlj4qfxivynv6bqd.onion/log.php' |
|
|
|
|
|
|
|
|
baseURL = 'http://jw5e5sdywqupaqgtt43uq5ysfqpd2vzefl65s2fcjlj4qfxivynv6bqd.onion/' |
|
|
|
|
|
|
|
|
def login(driver): |
|
|
|
|
|
input("Press ENTER when CAPTCHA is complete and login page has loaded\n") |
|
|
|
|
|
|
|
|
|
|
|
# entering username and password into input boxes |
|
|
|
|
|
usernameBox = driver.find_element(by=By.XPATH, value='//input[@name="username"]') |
|
|
|
|
|
# Username here |
|
|
|
|
|
usernameBox.send_keys('aliciamykeys') |
|
|
|
|
|
passwordBox = driver.find_element(by=By.XPATH, value='//input[@name="password"]') |
|
|
|
|
|
# Password here |
|
|
|
|
|
passwordBox.send_keys('aliciawherearemykey$') |
|
|
|
|
|
|
|
|
|
|
|
input("Press ENTER when CAPTCHA is completed and you exit the newsletter\n") |
|
|
|
|
|
|
|
|
|
|
|
# wait for listing page show up (This Xpath may need to change based on different seed url) |
|
|
|
|
|
WebDriverWait(driver, 100).until(EC.visibility_of_element_located( |
|
|
|
|
|
(By.XPATH, '//*[@id="submit"]'))) |
|
|
|
|
|
|
|
|
|
|
|
def crawlForum(driver): |
|
|
|
|
|
|
|
|
|
|
|
print("Crawling the DarkBazar market") |
|
|
|
|
|
|
|
|
|
|
|
linksToCrawl = getInterestedLinks() |
|
|
|
|
|
|
|
|
|
|
|
i = 0 |
|
|
|
|
|
while i < len(linksToCrawl): |
|
|
|
|
|
link = linksToCrawl[i] |
|
|
|
|
|
print('Crawling :', link) |
|
|
|
|
|
try: |
|
|
|
|
|
has_next_page = True |
|
|
|
|
|
count = 0 |
|
|
|
|
|
|
|
|
|
|
|
while has_next_page: |
|
|
|
|
|
try: |
|
|
|
|
|
driver.get(link) |
|
|
|
|
|
except: |
|
|
|
|
|
driver.refresh() |
|
|
|
|
|
html = driver.page_source |
|
|
|
|
|
savePage(html, link) |
|
|
|
|
|
|
|
|
|
|
|
list = productPages(html) |
|
|
|
|
|
|
|
|
|
|
|
for item in list: |
|
|
|
|
|
itemURL = urlparse.urljoin(baseURL, str(item)) |
|
|
|
|
|
try: |
|
|
|
|
|
driver.get(itemURL) |
|
|
|
|
|
except: |
|
|
|
|
|
driver.refresh() |
|
|
|
|
|
savePage(driver.page_source, item) |
|
|
|
|
|
driver.back() |
|
|
|
|
|
|
|
|
|
|
|
# comment out |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
# comment out |
|
|
|
|
|
if count == 1: |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
link = driver.find_element(by=By.XPATH, value='//a[contains(text(), "Next")]').get_attribute('href') |
|
|
|
|
|
if link == "": |
|
|
|
|
|
raise NoSuchElementException |
|
|
|
|
|
count += 1 |
|
|
|
|
|
|
|
|
|
|
|
except NoSuchElementException: |
|
|
|
|
|
has_next_page = False |
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
print(link, e) |
|
|
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
|
|
input("Crawling DarkBazar forum done sucessfully. Press ENTER to continue\n") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def savePage(page, url): |
|
|
|
|
|
cleanPage = cleanHTML(page) |
|
|
|
|
|
filePath = getFullPathName(url) |
|
|
|
|
|
os.makedirs(os.path.dirname(filePath), exist_ok=True) |
|
|
|
|
|
open(filePath, 'wb').write(cleanPage.encode('utf-8')) |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
def getInterestedLinks(): |
|
|
|
|
|
links = [] |
|
|
|
|
|
|
|
|
|
|
|
links.append('http://jw5e5sdywqupaqgtt43uq5ysfqpd2vzefl65s2fcjlj4qfxivynv6bqd.onion/cat.php?category=5') |
|
|
|
|
|
|
|
|
|
|
|
return links |
|
|
|
|
|
|
|
|
|
|
|
def crawler(): |
|
|
|
|
|
startCrawling() |
|
|
|
|
|
def startCrawling(): |
|
|
def startCrawling(): |
|
|
opentor() |
|
|
|
|
|
|
|
|
# opentor() |
|
|
mktName = getMKTName() |
|
|
mktName = getMKTName() |
|
|
driver = getAccess() |
|
|
driver = getAccess() |
|
|
|
|
|
|
|
@ -129,7 +42,8 @@ def startCrawling(): |
|
|
print(driver.current_url, e) |
|
|
print(driver.current_url, e) |
|
|
closetor(driver) |
|
|
closetor(driver) |
|
|
|
|
|
|
|
|
# new_parse(mktName, baseURL, False) |
|
|
|
|
|
|
|
|
new_parse(mktName, baseURL, True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Opens Tor Browser |
|
|
# Opens Tor Browser |
|
|
def opentor(): |
|
|
def opentor(): |
|
@ -143,14 +57,16 @@ def opentor(): |
|
|
input('Tor Connected. Press ENTER to continue\n') |
|
|
input('Tor Connected. Press ENTER to continue\n') |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Returns the name of the website |
|
|
# Returns the name of the website |
|
|
def getMKTName(): |
|
|
def getMKTName(): |
|
|
name = 'DarkBazar' |
|
|
name = 'DarkBazar' |
|
|
return name |
|
|
return name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Return the base link of the website |
|
|
# Return the base link of the website |
|
|
def getFixedURL(): |
|
|
def getFixedURL(): |
|
|
url = 'http://jw5e5sdywqupaqgtt43uq5ysfqpd2vzefl65s2fcjlj4qfxivynv6bqd.onion/log.php' |
|
|
|
|
|
|
|
|
url = 'http://jw5e5sdywqupaqgtt43uq5ysfqpd2vzefl65s2fcjlj4qfxivynv6bqd.onion/' |
|
|
return url |
|
|
return url |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -164,6 +80,7 @@ def closetor(driver): |
|
|
time.sleep(3) |
|
|
time.sleep(3) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Creates FireFox 'driver' and configure its 'Profile' |
|
|
# Creates FireFox 'driver' and configure its 'Profile' |
|
|
# to use Tor proxy and socket |
|
|
# to use Tor proxy and socket |
|
|
def createFFDriver(): |
|
|
def createFFDriver(): |
|
@ -179,9 +96,9 @@ def createFFDriver(): |
|
|
ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True) |
|
|
ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True) |
|
|
ff_prof.set_preference("signon.rememberSignons", False) |
|
|
ff_prof.set_preference("signon.rememberSignons", False) |
|
|
ff_prof.set_preference("network.cookie.lifetimePolicy", 2) |
|
|
ff_prof.set_preference("network.cookie.lifetimePolicy", 2) |
|
|
ff_prof.set_preference("network.dns.disablePrefetch", True) |
|
|
|
|
|
ff_prof.set_preference("network.http.sendRefererHeader", 0) |
|
|
|
|
|
ff_prof.set_preference("permissions.default.image", 2) |
|
|
|
|
|
|
|
|
# ff_prof.set_preference("network.dns.disablePrefetch", True) |
|
|
|
|
|
# ff_prof.set_preference("network.http.sendRefererHeader", 0) |
|
|
|
|
|
ff_prof.set_preference("permissions.default.image", 1) |
|
|
ff_prof.set_preference("browser.download.folderList", 2) |
|
|
ff_prof.set_preference("browser.download.folderList", 2) |
|
|
ff_prof.set_preference("browser.download.manager.showWhenStarting", False) |
|
|
ff_prof.set_preference("browser.download.manager.showWhenStarting", False) |
|
|
ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain") |
|
|
ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain") |
|
@ -197,11 +114,10 @@ def createFFDriver(): |
|
|
|
|
|
|
|
|
driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service) |
|
|
driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service) |
|
|
|
|
|
|
|
|
|
|
|
driver.maximize_window() |
|
|
|
|
|
|
|
|
return driver |
|
|
return driver |
|
|
|
|
|
|
|
|
def productPages(html): |
|
|
|
|
|
soup = BeautifulSoup(html, "html.parser") |
|
|
|
|
|
return darkbazar_links_parser(soup) |
|
|
|
|
|
|
|
|
|
|
|
#the driver 'gets' the url, attempting to get on the site, if it can't access return 'down' |
|
|
#the driver 'gets' the url, attempting to get on the site, if it can't access return 'down' |
|
|
def getAccess(): |
|
|
def getAccess(): |
|
@ -214,10 +130,40 @@ def getAccess(): |
|
|
driver.close() |
|
|
driver.close() |
|
|
return 'down' |
|
|
return 'down' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def login(driver): |
|
|
|
|
|
input("Press ENTER when CAPTCHA is complete and login page has loaded\n") |
|
|
|
|
|
|
|
|
|
|
|
# entering username and password into input boxes |
|
|
|
|
|
usernameBox = driver.find_element(by=By.XPATH, value='//input[@name="username"]') |
|
|
|
|
|
# Username here |
|
|
|
|
|
usernameBox.send_keys('aliciamykeys') |
|
|
|
|
|
passwordBox = driver.find_element(by=By.XPATH, value='//input[@name="password"]') |
|
|
|
|
|
# Password here |
|
|
|
|
|
passwordBox.send_keys('aliciawherearemykey$') |
|
|
|
|
|
# session time |
|
|
|
|
|
session_select = Select(driver.find_element(by=By.XPATH, value='/html/body/main/div/div/div/div/div/form/div[4]/div/div[2]/select')) |
|
|
|
|
|
session_select.select_by_visible_text('Session 60min') |
|
|
|
|
|
|
|
|
|
|
|
input("Press ENTER when CAPTCHA is completed and you exit the newsletter\n") |
|
|
|
|
|
|
|
|
|
|
|
# wait for listing page show up (This Xpath may need to change based on different seed url) |
|
|
|
|
|
WebDriverWait(driver, 100).until(EC.visibility_of_element_located( |
|
|
|
|
|
(By.XPATH, '//*[@id="submit"]'))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def savePage(driver, page, url): |
|
|
|
|
|
cleanPage = cleanHTML(driver, page) |
|
|
|
|
|
filePath = getFullPathName(url) |
|
|
|
|
|
os.makedirs(os.path.dirname(filePath), exist_ok=True) |
|
|
|
|
|
open(filePath, 'wb').write(cleanPage.encode('utf-8')) |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getFullPathName(url): |
|
|
def getFullPathName(url): |
|
|
from Forums.Initialization.forums_mining import config, CURRENT_DATE |
|
|
|
|
|
|
|
|
from MarketPlaces.Initialization.markets_mining import config, CURRENT_DATE |
|
|
|
|
|
|
|
|
mainDir = os.path.join(config.get('Project', 'shared_folder'), "Forums/" + getForumName() + "/HTML_Pages") |
|
|
|
|
|
|
|
|
mainDir = os.path.join(config.get('Project', 'shared_folder'), "MarketPlaces/" + getForumName() + "/HTML_Pages") |
|
|
fileName = getNameFromURL(url) |
|
|
fileName = getNameFromURL(url) |
|
|
if isDescriptionLink(url): |
|
|
if isDescriptionLink(url): |
|
|
fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html') |
|
|
fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html') |
|
@ -225,6 +171,88 @@ def getFullPathName(url): |
|
|
fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html') |
|
|
fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html') |
|
|
return fullPath |
|
|
return fullPath |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getForumName() -> str: |
|
|
|
|
|
name = 'DarkBazar' |
|
|
|
|
|
return name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getNameFromURL(url): |
|
|
|
|
|
global counter |
|
|
|
|
|
name = ''.join(e for e in url if e.isalnum()) |
|
|
|
|
|
if name == '': |
|
|
|
|
|
name = str(counter) |
|
|
|
|
|
counter = counter + 1 |
|
|
|
|
|
return name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getInterestedLinks(): |
|
|
|
|
|
links = [] |
|
|
|
|
|
|
|
|
|
|
|
# # Digital Goods |
|
|
|
|
|
# links.append('http://jw5e5sdywqupaqgtt43uq5ysfqpd2vzefl65s2fcjlj4qfxivynv6bqd.onion/cat.php?category=4') |
|
|
|
|
|
# Services |
|
|
|
|
|
links.append('http://jw5e5sdywqupaqgtt43uq5ysfqpd2vzefl65s2fcjlj4qfxivynv6bqd.onion/cat.php?category=5') |
|
|
|
|
|
|
|
|
|
|
|
return links |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def crawlForum(driver): |
|
|
|
|
|
|
|
|
|
|
|
print("Crawling the DarkBazar market") |
|
|
|
|
|
|
|
|
|
|
|
linksToCrawl = getInterestedLinks() |
|
|
|
|
|
|
|
|
|
|
|
i = 0 |
|
|
|
|
|
while i < len(linksToCrawl): |
|
|
|
|
|
link = linksToCrawl[i] |
|
|
|
|
|
print('Crawling :', link) |
|
|
|
|
|
try: |
|
|
|
|
|
has_next_page = True |
|
|
|
|
|
count = 0 |
|
|
|
|
|
|
|
|
|
|
|
while has_next_page: |
|
|
|
|
|
try: |
|
|
|
|
|
driver.get(link) |
|
|
|
|
|
except: |
|
|
|
|
|
driver.refresh() |
|
|
|
|
|
html = driver.page_source |
|
|
|
|
|
savePage(driver, html, link) |
|
|
|
|
|
|
|
|
|
|
|
list = productPages(html) |
|
|
|
|
|
|
|
|
|
|
|
for item in list: |
|
|
|
|
|
itemURL = urlparse.urljoin(baseURL, str(item)) |
|
|
|
|
|
try: |
|
|
|
|
|
driver.get(itemURL) |
|
|
|
|
|
except: |
|
|
|
|
|
driver.refresh() |
|
|
|
|
|
savePage(driver, driver.page_source, item) |
|
|
|
|
|
driver.back() |
|
|
|
|
|
|
|
|
|
|
|
# comment out |
|
|
|
|
|
# break |
|
|
|
|
|
|
|
|
|
|
|
# comment out |
|
|
|
|
|
if count == 1: |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
link = driver.find_element(by=By.XPATH, value='//a[contains(text(), "Next")]').get_attribute('href') |
|
|
|
|
|
if link == "": |
|
|
|
|
|
raise NoSuchElementException |
|
|
|
|
|
count += 1 |
|
|
|
|
|
|
|
|
|
|
|
except NoSuchElementException: |
|
|
|
|
|
has_next_page = False |
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
print(link, e) |
|
|
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
|
|
print("Crawling the DarkBazar market done.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Returns 'True' if the link is Topic link, may need to change for every website |
|
|
# Returns 'True' if the link is Topic link, may need to change for every website |
|
|
def isDescriptionLink(url): |
|
|
def isDescriptionLink(url): |
|
|
if 'item' in url: |
|
|
if 'item' in url: |
|
@ -238,15 +266,11 @@ def isListingLink(url): |
|
|
return True |
|
|
return True |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
def getForumName() -> str: |
|
|
|
|
|
name = 'DarkBazar' |
|
|
|
|
|
return name |
|
|
|
|
|
|
|
|
|
|
|
def getNameFromURL(url): |
|
|
|
|
|
global counter |
|
|
|
|
|
name = ''.join(e for e in url if e.isalnum()) |
|
|
|
|
|
if name == '': |
|
|
|
|
|
name = str(counter) |
|
|
|
|
|
counter = counter + 1 |
|
|
|
|
|
return name |
|
|
|
|
|
|
|
|
def productPages(html): |
|
|
|
|
|
soup = BeautifulSoup(html, "html.parser") |
|
|
|
|
|
return darkbazar_links_parser(soup) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def crawler(): |
|
|
|
|
|
startCrawling() |