# Hack Web Views With A Selenium Python Bot

Hi fellow hacker😂,  do you want to increase your youtube views, page views or send traffic to your social media profiles, blog or bot-created analytics.
<center>
![images-removebg-preview (3).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639638438995/w01PYHSe-.png)
</center>
Today, we shall create a simple python web bot that opens a specific URL in a browser of your preference and get those views!

We shall be using Selenium! So, **What is Selenium**? <br>
Selenium is an open-source software suite of browser automation tools that automate web browser interactions, created for testing purposes.

### Selenium’s Tool Suite
We’re not going to exhaust you with a long explanation of Selenium’s tool suite (you can check that out on Selenium’s own  [website](https://www.seleniumhq.org/projects/)  if you want). Instead, we’ll give you a brief overview of the tools and their key differences.
<center>
![Selenium-Tools-removebg-preview.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639638200268/BtUOOp0N5.png)
</center>
🛠 **Selenium IDE** <br>
Selenium IDE is a Chrome, Firefox and Edge extension that makes it easy to record and playback tests in the browser.

🛠 **Selenium WebDriver** <br>
Selenium WebDriver drives a browser natively, as a real user would, either locally or on remote machines.

🛠 **Selenium Grid **<br>
Selenium Grid takes WebDriver to another level by running tests on many machines at the same time, cutting down on the time it takes to test on multiple browsers and operating systems.
<center>
![SeleniumTesting-removebg-preview.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639644456369/IcpyFbHyA.png)
</center>
On a high level, Selenium can help you test software by automating tests. Automated testing, as opposed to manual testing, is beneficial as it allows you to complete testing tasks faster and with fewer errors. 

### The Hack:
Since I am using Windows, I will use  [chocolatey](https://chocolatey.org/)  to install Selenium and therefore you must run in an elevated command. (Admin privileges or PowerShell)

<mark>
Chocolatey is a software management automation for Windows that wraps installers, executables, zips, and scripts into compiled packages.
</mark>

Chocolatey or Choco as it is sometimes referred to is a free, open-source package manager for Windows that is very similar to Apt or DNF in the Linux realm.

I think It comes  [installed by default](https://docs.chocolatey.org/en-us/faqs)  in Windows 10+ but if it is not installed, check out the official  [docs](https://docs.chocolatey.org/en-us/choco/setup)  for installing or this step by step guide by  [Liquid Web](https://www.liquidweb.com/kb/how-to-install-chocolatey-on-windows/).

To verify that Chocolatey is installed, we will use the ```choco``` command.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639639005792/-ozhxF_EY.png)

I am using python, so we install selenium first (might require elevated rights)
```
pip install selenium
```
Install the chrome driver or you can see other browser options or os options from  [here](https://www.selenium.dev/selenium/docs/api/py/index.html) .

```
choco install chromedriver
```
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639634446729/EyaD-uWG2.png)

You may add this to the path, but in this article, I won't! I will include it in my code! <br>
Mine installed here:  <br>
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639639930507/YyLKXjMzh.png)
```
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
``` 
The above code simply imports our dependencies: <br>
The ``` class selenium.webdriver.common.keys.Keys``` handles all Keys in Selenium Python. It contains a huge number of key  [methods](https://www.selenium.dev/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#module-selenium.webdriver.common.keys)  one can use in Selenium Python.

You can actually do a lot with this class!

So my path is:
```
path = "C:/ProgramData/chocolatey/lib/chromedriver/tools/chromedriver.exe"
```
Note the slashes used otherwise you will have ```os``` errors!

Creating the URL page I want to auto-view! Replace it with any link especially those that can be viewed publically without logging in and this applies to most websites like Youtube, Social Media, Blogs, GitHub etc..!
```
url = "https://www.youtube.com/watch?v=eZyr8afY4bk"
no_of_views = 50
duration = float(10)
``` 
The logic:
```
for i in range(0,no_of_views):
    browser = webdriver.Chrome(path)
    browser.get(url)
    browser.find_element_by_tag_name('body').send_keys(Keys.SPACE)
    
    time.sleep(duration)

    print(str(i+1) + " iterations done")
    browser.quit()
``` 
The ``` body```  tag loads the entire content.

Run the script:  ``` python web_view_bot.py```  <br>
The browser tap will auto pop up and close after the passed ``` time.sleep(duration)```  and this is what you will see:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639641742313/Sp2kc41UK.png)
You can change the timer regarding website restrictions, make necessary edits<br>
End of Day Output:
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1639635977760/KxVM1KG8h.png)
Please note that some methods might have been deprecated, consider reading official  [docs](https://selenium-python.readthedocs.io/) for the latest version.

If a website requires login, you can still use selenium or combine it with requests! Check my requests implementation  [article](https://blog.octachart.com/scraping-websites-that-require-login-in-python) .

That's It! See Full Code  [Here](https://github.com/Ronlin1/selenium-web-hack).

If you enjoyed reading, consider subscribing and reacting to this with love by sharing, commenting and any criticism is much welcome.

📢Follow me on  [Twitter](https://twitter.com/intent/follow?screen_name=AfroBoyUg):

**Ronnie Atuhaire**


