我已经成功构建并测试了登录到我的wordpress网站的硒脚本(使用python和chromedriver)。该应用程序可以在我的本地计算机上完美运行。但是,由于将其部署到Ubuntu服务器上,我的脚本触发了mod_security规则并阻止我登录到我的wordpress网站。
这与Cookie或其运行在服务器上有关吗?
任何帮助将不胜感激。 Mod_security Error
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import os
import shutil
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from dashboard.models import Site
import glob
def Backup():
prefs = {
'download.default_directory': r"/home/landon/app/static/dashboard/backups",
# 'download.default_directory': r"/Users/landonroddenberry/Documents/appThree/SITERACK_1.0/dashboard/static/dashboard/backups", #### USE only for local testing and devs #####
'download.prompt_for_download': False,
'download.extensions_to_open': 'xml',
'safebrowsing.enabled': True
}
chrome_path = r"/usr/bin/chromedriver"
# chrome_path = r"/Users/landonroddenberry/Documents/chromedriver" #### USE only for local testing and devs #####
WINDOW_SIZE = "1920,1080"
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs',prefs)
options.add_argument("start-maximized")
options.add_argument("--headless")
# options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--window-size=%s" % WINDOW_SIZE)
options.add_argument("--safebrowsing-disable-download-protection")
options.add_argument("safebrowsing-disable-extension-blacklist")
driver = webdriver.Chrome(executable_path=chrome_path, options=options)
logLink = "/wp-login.php"
AdminLink = "/wp-admin/"
page = "export.php/"
p_col = "https://"
sites = Site.objects.filter(active=True)
for site in sites:
print('')
print('now backing up ' + site.webUrl)
MainLink = (p_col + site.webUrl + AdminLink)
loginLink = (p_col + site.webUrl + logLink)
driver.get(loginLink)
time.sleep(5)
try:
driver.find_element_by_xpath('/html/body/div[1]/form/div[3]/a[1]').click()
time.sleep(3)
except:
print("no button to click")
try:
user_name_elem = driver.find_element_by_xpath('//*[@id="user_login"]')
user_name_elem.clear()
time.sleep(2)
user_name_elem.send_keys(site.u_admin)
time.sleep(2)
passworword_elem = driver.find_element_by_xpath('//*[@id="user_pass"]')
time.sleep(2)
passworword_elem.clear()
passworword_elem.send_keys(site.p_admin)
time.sleep(3)
passworword_elem.send_keys(Keys.RETURN)
time.sleep(5)
driver.save_screenshot('Backup_Conflict_' + site.webUrl + '.png') ##### USED FOR DEBUGGING #######
print('done logging-in')
time.sleep(10)
except:
driver.save_screenshot('Backup_Conflict_' + site.webUrl + '.png')
答案 0 :(得分:0)
如果您在Windows和Linux操作系统上使用相同的chromedriver,则十个将无法使用,则chromedriver对于所有操作系统都是单独的。
尝试下载适用于Linux操作系统的chromedriver。
希望这会有所帮助。