Question:
How do you use Firefox with Selenium in Python?
I originally set up a script that used chrome w/ selenium, but chrome, as you probably know, uses quite a bit of RAM. The lag this creates on a script running 24/7 is so bad it doesn’t even run much of the time.
I had trouble setting chrome up too, but I had been able to find solutions for it. One of the solutions I applied was going into the hidden file, “replit.nix”, and adding packages manually. However, I cannot find the package name for firefox. The name for chrome was:
pkgs.chromium
and
pkgs.chromedriver
Repl link:
https://replit.com/@NathanaelMoore1/ServerAutomation?v=1
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
ONE_DAY = 24 * 60 * 60 # seconds
x = 0
i = 0
while x == 0:
# I don't actually know what this stuff does.
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
# This is Google Chrome. Shoved into a variable called 'driver'
driver = webdriver.Chrome(options=chrome_options)
# Change the link to your server's vote site.
print("Loading site...")
driver.get("https://www.planetminecraft.com/server/the-stoned-golem/vote/")
# This makes the text box for the Minecraft username into a variable that we can work with.
print("Finding text box...")
name_txt_box = driver.find_element(By.NAME, 'mcname')
# Change the string to your Minecraft username.
print("Typing userame...")
name_txt_box.send_keys('EternallyBlue445')
# This submits the form, sending your vote.
print("Submitting...")
name_txt_box.submit()
# Closes browser.
print("Closing browser...")
driver.close()
# Counting how many times the code has run.
i+=1
print("Done!", i)
# Records the number of runs the script has made and puts the record into "data.txt"
f = open("data.txt", "a")
f.write(str(i) + "\n")
f.close()
# Lets the script sleep for 1 day
time.sleep(ONE_DAY)
print("The script failed after " + i + " runs.")
Replit.Nix
|
v
{ pkgs }: {
deps = [
pkgs.chromium
pkgs.chromedriver
pkgs.sudo
pkgs.python310Full
pkgs.replitPackages.prybar-python310
pkgs.replitPackages.stderred
];
env = {
PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
# Needed for pandas / numpy
pkgs.stdenv.cc.cc.lib
pkgs.zlib
# Needed for pygame
pkgs.glib
# Needed for matplotlib
pkgs.xorg.libX11
];
PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
LANG = "en_US.UTF-8";
STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
};
}