A couple of years ago, I started to learn Python to help build up my coding skills. I cobbled together some code to automate comments in WordPress. It was just a small project I did to try and test my ability to create a functional and working program.
A few weeks ago, I decided to revisit this code to see if it still worked. To my surprise, it didn’t work. AI spent a few hours trying to debug it and as it turns out I was using an outdated version of selenium. I decided to try and update the code to utilise the latest version to try and get it to work again.
Below is the code which you can use if you want to automate comments in WordPress.
##################################################
### Script To Copy Contents Of File To WebPage ###
#### Version 0.2 - Creation Date - 03/08/2022 ####
############# Author - Imp0st3r ##################
##################################################
# Python modules to import
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from time import sleep
import pyperclip
msg = open('comments.txt', 'r').read() # Enter the path to the file you wish to read from
options = Options()
options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get('https://my/web/target/') # Enter the website you wish to copy your data to
search_box = driver.find_element(By.NAME, 'author') # Search for the element on the web page called 'author'
search_box.send_keys('Enter a name') # Enter the name you wish to use
sleep (2)
eml_box = driver.find_element(By.NAME, 'email') # Search for the element on the web page called 'email'
eml_box.send_keys('MyName@MyDomain.com') # Enter the email address you wish to use
sleep (2)
msg_box = driver.find_element(By.NAME, 'comment') # Search for the element on the web page called 'comment'
pyperclip.copy(msg) # Using Payperclip copy the contents of the file opened above to the clipboard
msg_box.send_keys(Keys.CONTROL, 'v') # Using Selenium paste the contents from the clip board to the web site
sleep (3)
post_comment = driver.find_element(By.NAME, 'submit') # Search for the element on the web page called submit
post_comment.submit() # Submit post
driver.quit() # Quit program
Creating meaningless programs likes this enables me to learn more about coding and the more I practice the better (hopefully) I will get. If you want to learn something new, its always good to not only learn the theory but to put that theory into practice. Get out there and give it a go.
Stay safee and stay curious.
imp0st3r