+1 (512) 588 6950

Creating Darkweb Crawler using Python and Tor

Home/Creating Darkweb Crawler using...
Creating Darkweb Crawler using Python and Tor
Photo by Photoholgic on Unsplash

Web crawlers, also known as web spiders or web robots, are automated programs that browse the World Wide Web in a methodical, automated manner. They are designed to discover and index new and updated web pages, and to follow links between pages to discover new content. Web crawlers are an essential part of search engines, as they help to index and organize the vast amount of information on the internet.

There are many reasons why we use web crawlers. One of the primary reasons is to discover and index new web pages. As the internet continues to grow at a rapid pace, it is impossible for humans to manually discover and index every new webpage that is created. Web crawlers help to automate this process by continuously scanning the internet and discovering new pages that have not yet been indexed.

Another reason we use web crawlers is to update the index of existing web pages. When a web page is updated, the changes may not be immediately reflected in the search engine’s index. Web crawlers help to ensure that the index is up to date by regularly revisiting web pages and checking for updates.

Web crawlers also play an important role in the ranking of web pages in search engine results. Search engines use algorithms to determine the relevance and quality of a web page, and web crawlers help to gather data that is used in these algorithms. For example, a web crawler might analyze the content of a web page, the number and quality of links pointing to the page, and the overall structure of the website. This data is then used to determine the page’s ranking in the search engine results.

There are many benefits to using web crawlers. One of the main benefits is the ability to quickly and easily find information on the internet. Without web crawlers, it would be much more difficult to locate specific pieces of information, as it would require manually searching through every website on the internet. Web crawlers help to make this process more efficient by organizing and indexing the vast amount of information on the internet, making it much easier to find what you are looking for.

Another benefit of web crawlers is the ability to track changes to websites over time. Web crawlers can keep a record of changes to websites, allowing users to see how a website has evolved over time. This can be especially useful for researchers and businesses who want to track trends and changes in their industry.

Web crawlers are also important in the field of dark web monitoring. The dark web is a part of the internet that is not indexed by traditional search engines, and it can be accessed only through special software such as the TOR network. The dark web is often used for illegal activity, such as the sale of drugs, weapons, and stolen personal information. Web crawlers can be used to monitor the dark web and gather intelligence on illegal activity, helping law enforcement agencies to track down and prosecute those involved.

import time
import requests
from stem import Signal
from stem.control import Controller
from bs4 import BeautifulSoup

# Set the number of links to crawl
num_links_to_crawl = 100

# Set the user agent to use for the request
user_agent = ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36’

# Set the headers for the request
headers = {‘User-Agent’: user_agent}

# Initialize the controller for the Tor network
with Controller.from_port(port=9051) as controller:
# Set the controller password

# Set the starting URL
url = ‘’

# Initialize the visited set and the link queue
visited = set()
queue = [url]

# Get the list of keywords to search for
keywords = input(‘Enter a list of keywords to search for, separated by commas: ‘).split(‘,’)

# Crawl the links
while queue:
# Get the next link in the queue
link = queue.pop(0)

# Skip the link if it has already been visited
if link in visited:

# Set the new IP address

# Send the request to the URL
response = requests.get(link, headers=headers)

# Parse the response
soup = BeautifulSoup(response.text, ‘html.parser’)

# Find all links on the page
links = soup.find_all(‘a’)

# Add any links that contain the keywords to the queue
for a in links:
href = a.get(‘href’)
if any(keyword in href for keyword in keywords):

# Add the link to the visited set

# Print the title and URL of the page
print(soup.title.string, link)

# Check if the number of visited links has reached the limit
if len(visited) >= num_links_to_crawl:

# Print the visited links
print(‘Visited links:’)
for link in visited:


The Python script we will be examining is designed to crawl websites using the TOR browser, with a new random IP generated every 10 seconds. This is useful for a number of reasons. For one, using TOR can help to protect the privacy of the web crawler, as it routes internet traffic through a network of servers to obscure the origin of the request. Additionally, using a new IP address every 10 seconds helps to avoid being detected and blocked by website servers.

To run this Python script, you will need to have the following prerequisites
1. Python: You will need to have Python installed on your machine in
order to run the script. You can download and install the latest version 
of Python from the official website (
2. TOR: You will need to have the TOR browser and the TOR control port 
installed and configured on your machine in order for the script to 
work properly. You can find instructions for installing and configuring 
TOR on Windows on the TOR website (
3. Libraries: The script uses the following Python libraries, which you 
will need to install in order to run the script:
i. requests: A library for sending HTTP requests and receiving responses.
ii. stem: A library for interacting with the TOR control port.
iii. BeautifulSoup: A library for parsing HTML and extracting information 
from web pages.

One of the main advantages of using Python to build a web crawler is the vast number of libraries and frameworks available for web scraping and data processing. Python has a large and active community of developers, and as a result there are many libraries and frameworks that can be used to simplify the process of building a web crawler. For example, the script uses the BeautifulSoup library to parse HTML and extract links and other information from web pages, and the requests library to send HTTP requests and retrieve web pages.

Another advantage of using Python for web crawling is the simplicity of the language. Python is known for its readability and simplicity, which makes it easier to write and debug code. This is especially important when building a web crawler, as the process of crawling the web can be complex and error-prone. With Python, it is easier to write code that is clear and easy to understand, which can help to reduce the risk of errors and improve the overall efficiency of the web crawler.

One of the benefits of the Python script we have examined is the ability to search for keywords in websites and perform snowball sampling crawling. This is useful for finding specific pieces of information on the internet, as it allows the web crawler to focus on websites that are likely to contain the information that is being sought. The script also prints the titles of the pages it visits, which can be helpful for identifying relevant web pages.

Overall, the Python script we have examined is a useful tool for building a web crawler that can crawl websites using TOR and search for keywords. The advantages and benefits of using Python for web crawling are numerous, including the vast number of libraries and frameworks available for web scraping and data processing, the simplicity of the language, and the ability to search for keywords and perform snowball sampling crawling. Whether you are a researcher, a business owner, or simply someone who wants to find information on the internet, a Python-based web crawler can be a valuable tool.

In conclusion, web crawlers are an essential tool for organizing and indexing the vast amount of information on the internet. They play a crucial role in the discovery and ranking of web pages, and are used by search engines to help users find the information they are looking for. Web crawlers also have the ability to track changes to websites over time, and are important in the field of dark web monitoring. Overall, the benefits and importance of web crawlers cannot be understated, as they help to make the vast and constantly-changing landscape of the internet more accessible and easier to navigate.

Leave a Reply