<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Clickbot Archives - Tutorial Tech</title>
	<atom:link href="https://tutorialtech.net/category/clickbot/feed/" rel="self" type="application/rss+xml" />
	<link>https://tutorialtech.net/category/clickbot/</link>
	<description>Tutorials, Security, Technology</description>
	<lastBuildDate>Tue, 14 Jun 2022 10:27:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.1</generator>

<image>
	<url>https://tutorialtech.net/wp-content/uploads/2020/05/cropped-tut_tech_logo-32x32.jpg</url>
	<title>Clickbot Archives - Tutorial Tech</title>
	<link>https://tutorialtech.net/category/clickbot/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">175782066</site>	<item>
		<title>Orteil Cookie Clicker Bot with python selenium</title>
		<link>https://tutorialtech.net/orteil-cookie-clicker-bot-with-python-selenium/</link>
					<comments>https://tutorialtech.net/orteil-cookie-clicker-bot-with-python-selenium/#respond</comments>
		
		<dc:creator><![CDATA[Julius Reinhardt]]></dc:creator>
		<pubDate>Sun, 26 Apr 2020 20:22:39 +0000</pubDate>
				<category><![CDATA[Clickbot]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://tutorialtech.net/?p=216</guid>

					<description><![CDATA[<p>In this tutorial, I will show you how to write a Clickbot for the famous Cookie Clicker game by orteil. With this little hack, you can click as fast as your hardware allows to generate endless cookies. We will use python3 and a module called selenium. It is mostly used for testing websites but also [&#8230;]</p>
<p>The post <a href="https://tutorialtech.net/orteil-cookie-clicker-bot-with-python-selenium/">Orteil Cookie Clicker Bot with python selenium</a> appeared first on <a href="https://tutorialtech.net">Tutorial Tech</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this tutorial, I will show you how to write a Clickbot for the famous <a href="https://orteil.dashnet.org/cookieclicker/" target="_blank" rel="noreferrer noopener">Cookie Clicker game by orteil</a>. With this little hack, you can click as fast as your hardware allows to generate endless cookies. We will use python3 and a module called <em>selenium</em>. It is mostly used for testing websites but also the perfect tool for automating tasks like rapid clicking on a cookie.  </p>



<h2 class="wp-block-heading">How does selenium work?</h2>



<p class="wp-block-paragraph">Selenium is basically a testing framework for websites and compatible with Windows, Mac and Linux. It uses a Webdriver to access the installed Browser to simulate user interaction. In this tutorial, I will use the <a href="https://chromedriver.chromium.org" rel="noreferrer noopener">chromedriver</a> for Google Chrome Browser, but you can use any driver by modifying the code. In Firefox&#8217;s case it&#8217;s called <a href="https://github.com/mozilla/geckodriver/releases" rel="noreferrer noopener">Geckodriver</a> and can be download from the <a href="https://github.com/mozilla/geckodriver/releases" rel="noreferrer noopener">official Github Page.</a> </p>



<h2 class="wp-block-heading">Cookie Clickbot in action </h2>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="896" src="https://tutorialtech.net/wp-content/uploads/2020/04/Screen-Shot-2020-04-26-at-15.37.26-1-1024x896.png" alt="Cookie Clickbot in action" class="wp-image-226" srcset="https://tutorialtech.net/wp-content/uploads/2020/04/Screen-Shot-2020-04-26-at-15.37.26-1-1024x896.png 1024w, https://tutorialtech.net/wp-content/uploads/2020/04/Screen-Shot-2020-04-26-at-15.37.26-1-300x262.png 300w, https://tutorialtech.net/wp-content/uploads/2020/04/Screen-Shot-2020-04-26-at-15.37.26-1-768x672.png 768w, https://tutorialtech.net/wp-content/uploads/2020/04/Screen-Shot-2020-04-26-at-15.37.26-1-1536x1343.png 1536w, https://tutorialtech.net/wp-content/uploads/2020/04/Screen-Shot-2020-04-26-at-15.37.26-1-2048x1791.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Let&#8217;s look at the python code</h2>



<pre class="wp-block-code"><code>from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time, sys

class cookieBot():
    def __init__(self):
        self.browser = webdriver.Chrome(sys.argv&#91;1])
        self.browser.get("https://orteil.dashnet.org/cookieclicker/")
        WebDriverWait(self.browser, 4).until(EC.presence_of_element_located((By.ID, 'bigCookie')))       </code></pre>



<p class="wp-block-paragraph">In the beginning, we import <em>WebDriver</em>, which will open and control the browser. With <em>WebDriverWait</em> and <em>EC</em>, we can wait until <strong>e</strong>xpected <strong>c</strong>onditions are met, for example a specific element has loaded. We use <em>By</em> to easily identify elements in the DOM of the website and <em>time</em> to wait for a specific duration in seconds.</p>



<p class="wp-block-paragraph">In the next step, we create the class <em>cookieBot</em> with a constructor opening the Cookie Clicker Website and wait until the page has fully loaded. If you want to use Firefox instead of Chrome, you can modify <em>self.browser</em> to:</p>



<pre class="wp-block-code"><code>self.browser = webdriver.Firefox(sys.argv&#91;1])</code></pre>



<p class="wp-block-paragraph">Keep in mind that you need the corresponding GeckoDriver for your Firefox version. You can download the latest one from the official Github Page <a href="https://github.com/mozilla/geckodriver/releases" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p class="wp-block-paragraph">The next line is opening Cookie Clickers Website in the browser. After that we want to wait until the clickable Cookie has loaded, otherwise the program will throw an error on access.  This is done by WebDriverWait with the expected condition that an element with id=bigCookie has already loaded. </p>



<h2 class="wp-block-heading">Performing the automated click</h2>



<p class="wp-block-paragraph">Now we declare the class function <em>clickCookie()</em>. It will be called in an endless loop later to perform the click on the Cookie to generate income. Therefore we use the selenium built-in function <em>find_element_by_id</em>() to identify the Cookie. In the next instruction we click on it. </p>



<pre class="wp-block-code"><code>def clickCookie(self):
    cookie = self.browser.find_element_by_id('bigCookie')
    cookie.click()</code></pre>



<h2 class="wp-block-heading">Program flow</h2>



<p class="wp-block-paragraph">At first we create an object of the class cookieBot. This will open the browser and open Cookie Clicker&#8217;s page. After that we wait for one second. Therefore the browser has time to load all remaining resources to build the page. In the end we execute an infinite loop clicking on the cookie.   </p>



<pre class="wp-block-code"><code>bot = cookieBot()
time.sleep(1)
while(True):
    bot.clickCookie()</code></pre>



<p class="wp-block-paragraph">You can clone the <a rel="noreferrer noopener" href="https://github.com/jreinhardt2/CookieClicker" target="_blank">GitHub repository</a> containing the whole code with the following command:</p>



<pre class="wp-block-code"><code>git clone https://github.com/jreinhardt2/CookieClicker.git</code></pre>



<h2 class="wp-block-heading">Execution </h2>



<p class="wp-block-paragraph">After cloning the repository and changing into root directory, you can execute the Clickbot with following command:</p>



<pre class="wp-block-code"><code>python3 clicker.py "path_to_chromedriver"</code></pre>



<p class="wp-block-paragraph">The repository contains the corresponding driver for Windows, Mac and Linux. It&#8217;s important to specify the path to the file. You can either use an absolute path like: </p>



<pre class="wp-block-code"><code>python3 clicker.py "/Users/Julius/Documents/CookieClicker/chromedriver_mac"</code></pre>



<p class="wp-block-paragraph">or a relative path like:</p>



<pre class="wp-block-code"><code>python3 clicker.py "./chromedriver_mac"</code></pre>



<p class="wp-block-paragraph">Remember to not forget <strong>./</strong> at the beginning of the relative path!</p>



<h2 class="wp-block-heading">Clickbot code in python</h2>



<pre class="wp-block-code"><code>from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time, sys

if len(sys.argv) &lt; 2:
    print('Usage: python clicker.py "path_to_chromedriver" || In same directory add ./ before chromedriver')
    sys.exit(-1)

class cookieBot():
    def __init__(self):
        self.browser = webdriver.Chrome(sys.argv&#91;1])
        self.browser.get("https://orteil.dashnet.org/cookieclicker/")
        WebDriverWait(self.browser, 4).until(EC.presence_of_element_located((By.ID, 'bigCookie')))


    def clickCookie(self):
        cookie = self.browser.find_element_by_id('bigCookie')
        cookie.click()

bot = cookieBot()
time.sleep(1)
while(True):
    bot.clickCookie()
        </code></pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">As you can see it is possible with selenium to use very little code to write a Clickbot for Cookie Clicker. You can apply this tutorial to every element on a desired website you want to click. </p>



<p class="wp-block-paragraph">If you are interested in how I started this blog you can check it out <a href="https://tutorialtech.net/my-wordpress-blog-with-amazon-aws/">here</a> or if you always wanted to know how to decrypt Nodejs TLS traffic you can check <a href="https://tutorialtech.net/how-to-decrypt-nodejs-tls-traffic-with-wireshark/">here</a>.</p>
<p>The post <a href="https://tutorialtech.net/orteil-cookie-clicker-bot-with-python-selenium/">Orteil Cookie Clicker Bot with python selenium</a> appeared first on <a href="https://tutorialtech.net">Tutorial Tech</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tutorialtech.net/orteil-cookie-clicker-bot-with-python-selenium/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">216</post-id>	</item>
	</channel>
</rss>
