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.

314 lines
10 KiB

1 year ago
1 year ago
  1. __author__ = 'Helium'
  2. '''
  3. Procrax Forum Crawler (Selenium)
  4. rechecked and confirmed
  5. '''
  6. from selenium import webdriver
  7. from selenium.common.exceptions import NoSuchElementException
  8. from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
  9. from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  10. from selenium.webdriver.firefox.service import Service
  11. from selenium.webdriver.common.by import By
  12. from selenium.webdriver.support import expected_conditions as EC
  13. from selenium.webdriver.support.ui import WebDriverWait
  14. from PIL import Image
  15. import urllib.parse as urlparse
  16. import os, re, time
  17. from datetime import date
  18. import configparser
  19. import subprocess
  20. from bs4 import BeautifulSoup
  21. from Forums.Initialization.prepare_parser import new_parse
  22. from Forums.Procrax.parser import procrax_links_parser
  23. from Forums.Utilities.utilities import cleanHTML
  24. counter = 1
  25. BASE_URL = 'https://procrax.cx/'
  26. FORUM_NAME = 'Procrax'
  27. # Opens Tor Browser, crawls the website
  28. def startCrawling():
  29. driver = getAccess()
  30. if driver != 'down':
  31. try:
  32. login(driver)
  33. crawlForum(driver)
  34. except Exception as e:
  35. print(driver.current_url, e)
  36. closeDriver(driver)
  37. new_parse(forum=FORUM_NAME, url=BASE_URL, createLog=True)
  38. # Login using premade account credentials and do login captcha manually
  39. def login(driver):
  40. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  41. (By.XPATH, '/html/body/div[1]/div[3]/div[2]/div[3]/div[2]/div[1]/form/div/div/div/dl[4]/dd/div/div[2]/button/span')))
  42. #entering username and password into input boxes
  43. usernameBox = driver.find_element(by=By.NAME, value='login')
  44. #Username here
  45. usernameBox.send_keys('cheese_pizza_man')#sends string to the username box
  46. passwordBox = driver.find_element(by=By.NAME, value='password')
  47. #Password here
  48. passwordBox.send_keys('Gr33nSp@m&3ggs')# sends string to passwordBox
  49. clicker = driver.find_element(by=By.XPATH, value='/html/body/div[1]/div[3]/div[2]/div[3]/div[2]/div[1]/form/div/div/div/dl[4]/dd/div/div[2]/button/span')
  50. clicker.click()
  51. # # wait for listing page show up (This Xpath may need to change based on different seed url)
  52. # # wait for 50 sec until id = tab_content is found, then cont
  53. WebDriverWait(driver, 50).until(EC.visibility_of_element_located(
  54. (By.XPATH, '/html/body/div[1]/div[3]/div[2]/div[3]/div[1]/div/div[1]/div')))
  55. # Returns the name of the website
  56. def getForumName():
  57. name = 'Procrax'
  58. return name
  59. # Return the link of the website
  60. def getFixedURL():
  61. url = 'https://procrax.cx/'
  62. return url
  63. # Closes Tor Browser
  64. def closeDriver(driver):
  65. # global pid
  66. # os.system("taskkill /pid " + str(pro.pid))
  67. # os.system("taskkill /t /f /im tor.exe")
  68. print('Closing Tor...')
  69. driver.close() #close tab
  70. time.sleep(3)
  71. return
  72. # Creates FireFox 'driver' and configure its 'Profile'
  73. # to use Tor proxy and socket
  74. def createFFDriver():
  75. from Forums.Initialization.forums_mining import config
  76. ff_binary = FirefoxBinary(config.get('TOR', 'firefox_binary_path'))
  77. ff_prof = FirefoxProfile(config.get('TOR', 'firefox_profile_path'))
  78. ff_prof.set_preference("places.history.enabled", False)
  79. ff_prof.set_preference("privacy.clearOnShutdown.offlineApps", True)
  80. ff_prof.set_preference("privacy.clearOnShutdown.passwords", True)
  81. ff_prof.set_preference("privacy.clearOnShutdown.siteSettings", True)
  82. ff_prof.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
  83. ff_prof.set_preference("signon.rememberSignons", False)
  84. ff_prof.set_preference("network.cookie.lifetimePolicy", 2)
  85. ff_prof.set_preference("network.dns.disablePrefetch", True)
  86. ff_prof.set_preference("network.http.sendRefererHeader", 0)
  87. ff_prof.set_preference("permissions.default.image", 3)
  88. ff_prof.set_preference("browser.download.folderList", 2)
  89. ff_prof.set_preference("browser.download.manager.showWhenStarting", False)
  90. ff_prof.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
  91. ff_prof.set_preference('network.proxy.type', 1)
  92. ff_prof.set_preference("network.proxy.socks_version", 5)
  93. ff_prof.set_preference('network.proxy.socks', '127.0.0.1')
  94. ff_prof.set_preference('network.proxy.socks_port', 9150)
  95. ff_prof.set_preference('network.proxy.socks_remote_dns', True)
  96. ff_prof.set_preference("javascript.enabled", True)
  97. ff_prof.update_preferences()
  98. service = Service(config.get('TOR', 'geckodriver_path'))
  99. driver = webdriver.Firefox(firefox_binary=ff_binary, firefox_profile=ff_prof, service=service)
  100. driver.maximize_window()
  101. return driver
  102. def getAccess():
  103. driver = createFFDriver()
  104. try:
  105. driver.get(BASE_URL)# open url in browser
  106. return driver
  107. except:
  108. driver.close()# close tab
  109. return 'down'
  110. # Saves the crawled html page
  111. def savePage(driver, page, url):
  112. cleanPage = cleanHTML(driver, page)
  113. filePath = getFullPathName(url)
  114. os.makedirs(os.path.dirname(filePath), exist_ok=True)
  115. open(filePath, 'wb').write(cleanPage.encode('utf-8'))
  116. return
  117. # Gets the full path of the page to be saved along with its appropriate file name
  118. def getFullPathName(url):
  119. from Forums.Initialization.forums_mining import config, CURRENT_DATE
  120. mainDir = os.path.join(config.get('Project', 'shared_folder'), "Forums/" + FORUM_NAME + "/HTML_Pages")
  121. fileName = getNameFromURL(url)
  122. if isDescriptionLink(url):
  123. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Description\\' + fileName + '.html')
  124. else:
  125. fullPath = os.path.join(mainDir, CURRENT_DATE + r'\\Listing\\' + fileName + '.html')
  126. return fullPath
  127. # Creates the file name from passed URL
  128. def getNameFromURL(url):
  129. global counter
  130. name = ''.join(e for e in url if e.isalnum())
  131. if (name == ''):
  132. name = str(counter)
  133. counter = counter + 1
  134. return name
  135. def getInterestedLinks():
  136. links = []
  137. # verified sales
  138. links.append('https://procrax.cx/forums/verified-sales-market.10/')
  139. # unverified sales
  140. links.append('https://procrax.cx/forums/unverified-sales-market.12/')
  141. # combos
  142. links.append('https://procrax.cx/forums/bases.79/')
  143. # tools
  144. links.append('https://procrax.cx/forums/tools.81/')
  145. # configs
  146. links.append('https://procrax.cx/forums/configs.82/')
  147. # craxtube
  148. links.append('https://procrax.cx/forums/craxtube.83/')
  149. # general hacking
  150. links.append('https://procrax.cx/forums/general-hacking.24/')
  151. # hacking security tools
  152. links.append('https://procrax.cx/forums/hacking-security-tools.20/')
  153. # hacktube
  154. links.append('https://procrax.cx/forums/hacktube.22/')
  155. # cardingtube
  156. links.append('https://procrax.cx/forums/cardingtube.26/')
  157. # cardable
  158. links.append('https://procrax.cx/forums/cardable-websites.28/')
  159. # spam software
  160. links.append('https://procrax.cx/forums/mailing.72/')
  161. # spam tools
  162. links.append('https://procrax.cx/forums/tools-bots-validators.73/')
  163. # darknet news
  164. links.append('https://procrax.cx/forums/darknet-news-articles.42/')
  165. # links
  166. links.append('https://procrax.cx/forums/darknet-markets-deep-onion-links.43/')
  167. # courses
  168. links.append('https://procrax.cx/forums/courses.59/')
  169. # software
  170. links.append('https://procrax.cx/forums/software.76/')
  171. # general forum
  172. links.append('https://procrax.cx/forums/forum-discussions-updates.7/')
  173. return links
  174. def crawlForum(driver):
  175. print("Crawling the Procrax forum")
  176. linksToCrawl = getInterestedLinks()
  177. i = 0
  178. while i < len(linksToCrawl):
  179. link = linksToCrawl[i]
  180. print('Crawling :', link)
  181. try:
  182. has_next_page = True
  183. count = 0
  184. while has_next_page:
  185. try:
  186. driver.get(link)
  187. except:
  188. driver.refresh()
  189. html = driver.page_source
  190. savePage(driver, html, link)
  191. topics = topicPages(html)
  192. for topic in topics:
  193. has_next_topic_page = True
  194. counter = 1
  195. page = topic
  196. while has_next_topic_page:
  197. itemURL = urlparse.urljoin(BASE_URL, str(page))
  198. try:
  199. driver.get(itemURL)
  200. except:
  201. driver.refresh()
  202. savePage(driver, driver.page_source, topic + f"page{counter}") # very important
  203. # # comment out
  204. # if counter == 2:
  205. # break
  206. try:
  207. page = driver.find_element(By.LINK_TEXT, value='Next').get_attribute('href')
  208. if page == "":
  209. raise NoSuchElementException
  210. counter += 1
  211. except NoSuchElementException:
  212. has_next_topic_page = False
  213. for j in range(counter):
  214. driver.back()
  215. # # comment out
  216. # break
  217. #
  218. # # comment out
  219. # if count == 1:
  220. # break
  221. try:
  222. link = driver.find_element(by=By.LINK_TEXT, value='Next').get_attribute('href')
  223. if link == "":
  224. raise NoSuchElementException
  225. count += 1
  226. except NoSuchElementException:
  227. has_next_page = False
  228. except Exception as e:
  229. print(link, e)
  230. i += 1
  231. print("Crawling the Procrax forum done.")
  232. # Returns 'True' if the link is Topic link, may need to change for every website
  233. def isDescriptionLink(url):
  234. if 'threads' in url:
  235. return True
  236. return False
  237. # Returns True if the link is a listingPage link, may need to change for every website
  238. def isListingLink(url):
  239. if 'forums' in url:
  240. return True
  241. return False
  242. # calling the parser to define the links
  243. def topicPages(html):
  244. soup = BeautifulSoup(html, "html.parser")
  245. #print(soup.find('div', id="container").find('div', id="content").find('table', {"class": "tborder clear"}).find('tbody').find('tr',{"class": "inline_row"}).find('strong').text)
  246. return procrax_links_parser(soup)
  247. def crawler():
  248. startCrawling()
  249. # print("Crawling and Parsing BestCardingWorld .... DONE!")