Post

Web Bot

Python script that automatically browses a webpage and clicks the buttons for you.

Python script

This script uses the selenium python module to click buttons for you, and it even scrolls the webpage if the button is out of view. You will of course need to collect the button elements from the webpage, which can be easily done using Developer tools in the Chrome browser.

The cookies and cache also get’s cleared everytime the browser opens.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import ElementClickInterceptedException, ElementNotInteractableException, TimeoutException, NoSuchElementException
import requests
import time


# Configure Tor proxy
socks_proxy = "127.0.0.1:9150"  # Default Tor SOCKS proxy

def setup_chrome_options():
    chrome_options = Options()
    # chrome_options.add_argument(f"--proxy-server=socks5://{socks_proxy}")
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    chrome_options.add_argument("--disable-features=NetworkService,NetworkServiceInProcess")
    chrome_options.add_argument("--disable-extensions")
    chrome_options.add_argument("--incognito")
    chrome_options.add_argument("--disable-popup-blocking")
    chrome_options.add_argument("--disable-automation")
    chrome_options.add_argument("--disable-gpu")
    chrome_options.add_argument("start-maximized")
    chrome_options.add_argument("disable-infobars")
    chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")

    # Enable cookies
    chrome_options.add_experimental_option("prefs", {
        "profile.default_content_setting_values.cookies": 1,
        "profile.default_content_setting_values.third_party_cookies": 1
    })
    
    return chrome_options

def solve_captcha(site_key, url):
    api_key = ''
    s = requests.Session()
    captcha_id = s.post("http://2captcha.com/in.php", data={"key": api_key, "method": "userrecaptcha", "googlekey": site_key, "pageurl": url}).test.split('|')[1]
    # Polling for the results
    result = s.get(f"http://2captcha.com/res.php?key={api_key}&action=get&id={captia_id}")
    while 'CAPCHA_NOT_READY' in result.text:
        time.sleep(5)
        result = s.get(f"http://2captcha.com/res.php?key={api_key}&action=get&id={captia_id}")
    return result.text.split('|')[1]


# Get the Chrome options
chrome_options = setup_chrome_options()

# Initialize the WebDriver with the options
driver = webdriver.Chrome(options=chrome_options)  # Make sure the ChromeDriver is in your PATH



# Clear the browser cache and cookies
driver.get("https://example.org/vote")  # Replace with your target URL
driver.delete_all_cookies()
driver.execute_script("window.localStorage.clear();")
driver.execute_script("window.sessionStorage.clear();")
driver.execute_script("caches.keys().then(function(names) { for (let name of names) caches.delete(name); });")
time.sleep(2)  # Add a slight delay to ensure the cache and cookies are cleared


# Open the webpage
#driver.get("https://example.org/vote")  # Replace with your target URL

try:
    
 # Wait for the CAPTCHA to be manually solved
    #input("Please solve the CAPTCHA and then press Enter to continue...")

     # Interact with the 'Services' element
    try:
        element = WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.XPATH, "//p[text()='Example button']"))
        )
        driver.execute_script("arguments[0].scrollIntoView(true);", element)
        element.click()
        time.sleep(1)
    except TimeoutException:
        print("Timeout: 'Services' element not found")
        driver.quit()
        exit()

    # Wait until the 'Business Solutions Provider' button is present
    try:
        button = WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.XPATH, "//button[contains(normalize-space(text()),'Example button')]"))
        )
        driver.execute_script("arguments[0].scrollIntoView(true);", button)
        try:
            button.click()
            time.sleep(1)
        except ElementClickInterceptedException:
            driver.execute_script("arguments[0].click();", button)
    except TimeoutException:
        print("Timeout: 'Business Solutions Provider' button not found")
        driver.quit()
        exit()
    except NoSuchElementException:
        print("No Such Element")
        driver.quit()
        exit()
    # Interact with the option button by ID
    try:
        checkbox = WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.XPATH, "//label[normalize-space(text())='Example Checkbox']"))
        )
        driver.execute_script("arguments[0].scrollIntoView(true);", checkbox)

        try:
            checkbox.click()
            time.sleep(1)
        except (ElementClickInterceptedException, ElementNotInteractableException):
            driver.execute_script("arguments[0].click();", checkbox)

    except TimeoutException:
        print("Timeout: Option button not found")
        driver.quit()
        exit()
    except NoSuchElementException:
        print("No Such Element ITO")
        driver.quit()
        exit()

    # Interact with the 'add-to-button active' button by class name
    try:
        button = WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.XPATH, "//button[text()='Add Vote']"))
        )
        driver.execute_script("arguments[0].scrollIntoView(true);", button)

        try:
            button.click()
            time.sleep(1)
        except ElementClickInterceptedException:
            driver.execute_script("arguments[0].click();", button)
    except TimeoutException:
        print("Timeout: 'add-to-button active' button not found")
        driver.quit()
        exit()

    # Interact with the 'submit-button active' button by class name
    try:
        button = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.XPATH, "//div[text()='Submit']"))
        )
        driver.execute_script("arguments[0].scrollIntoView(true);", button)

        try:
            button.click()
            time.sleep(2)
        except ElementClickInterceptedException:
            driver.execute_script("arguments[0].click();", button)

    except TimeoutException:
        print("Timeout: 'submit-button active' button not found")
        driver.quit()
        exit()
    
    #driver.delete_all_cookies()
    #driver.execute_script("window.localStorage.clear();")
    #driver.execute_script("window.sessionStorage.clear();")
    #driver.execute_script("caches.keys().then(function(names) { for (let name of names) caches.delete(name); });")
    
finally:
    # Close the browser after a delay to see the result of the click action
    import time
    time.sleep(3)  # Adjust the sleep time if needed
    driver.quit()

Shell script

Combine this with a shell script that connects to a nordvpn ovpn file, run the web-bot.py script, then disconnects from the vpn and loops again until the last ovpn file in the directory has been used. That’s over 6000 ovpn files, which means a new unique IP each time!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash

# Directory containing NordVPN .ovpn files
VPN_DIR="/home/berrick/Projects/nordscraper/nord_ovpn_tcp/sorted_various_ovpn_tcp"
# Python script to run
PYTHON_SCRIPT="/home/berrick/Projects/web-bot/web-bot.py"
# File to keep track of the count
COUNT_FILE="/home/berrick/Projects/nordscraper/count.txt"
# Path to the credentials file
CREDENTIALS_FILE="/home/berrick/Projects/nordscraper/credentials.txt"

# Check if the VPN directory exists
if [ ! -d "$VPN_DIR" ]; then
  echo "VPN directory not found!"
  exit 1
fi

# Check if the Python script exists
if [ ! -f "$PYTHON_SCRIPT" ]; then
  echo "Python script not found!"
  exit 1
fi

# Check if the credentials file exists
if [ ! -f "$CREDENTIALS_FILE" ]; then
  echo "Credentials file not found!"
  exit 1
fi

# Initialize count
if [ ! -f "$COUNT_FILE" ]; then
  echo "0" > "$COUNT_FILE"
fi

# Read the current count
count=$(cat "$COUNT_FILE")

# Get a list of all .ovpn files sorted alphabetically
OVPN_FILES=($(ls "$VPN_DIR"/*.ovpn | sort))
total_files=${#OVPN_FILES[@]}

if [ $total_files -eq 0 ]; then
  echo "No .ovpn files found in the directory!"
  exit 1
fi

index=0

while true; do
  # Select the next .ovpn file alphabetically
  OVPN_FILE=${OVPN_FILES[$index]}

  echo "Connecting to VPN using $OVPN_FILE..."
  sudo openvpn --config "$OVPN_FILE" --daemon --auth-user-pass "$CREDENTIALS_FILE"

  # Wait a few seconds to ensure the VPN connection is established
  sleep 10

  # Run the Python script
  echo "Running Python script..."
  python "$PYTHON_SCRIPT"

  # Disconnect from the VPN
  echo "Disconnecting from VPN..."
  sudo killall openvpn

  # Increment the count and display it
  count=$((count + 1))
  echo "Iteration count: $count"
  echo "$count" > "$COUNT_FILE"

  # Move to the next .ovpn file in the list
  index=$((index + 1))
 
  # Wait a few seconds before the next iteration
  sleep 5
done

echo "All .ovpn files have been processed. Exiting."
This post is licensed under CC BY 4.0 by the author.