Run Python Script with selenium functions and return the result back to PHP, where did i call the Python in first place (using Laravel)
Get the solution ↓↓↓I 'm in trouble many days now. I cannot find the way where i will pass variables and calling Python script from PHP. The Python script will be used to run Selenium with Chrome and after it runs for website testing will have to return back to PHP, where all started, the result of test. FYI i 'm using production stage on Laravel with the previous logic - structure, using Centos 7 with Plesk Obsydian server. To be more specific:
Laravel Controller:
public function setupTest($token, $title, $sku, $color){
$ip = $this->getProxies()->ip;
$port = $this->getProxies()->port;
$proxy = $ip.":".$port;
$output = passthru("python ".public_path()."/directory/test.py ".$proxy);
}
Then in the Python script i 'm doing the rest:
import sys
import os
import wget
import time
import sys
import urllib
import random
import xmltodict
import xml
import json
import codecs
import xlsxwriter
import smtplib
from random import randrange
from google import google
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.opera.options import Options
from bs4 import BeautifulSoup
from bs4 import BeautifulSoup as bs
from bs4 import BeautifulStoneSoup as Soup
def openDriver():
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options, executable_path=r'root_path_till_plesk_subscription_i_got_installed_laravel_into/public/py/chromedriver')
driver.execute_cdp_cmd("Network.enable", {})
driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {"headers": {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"}})
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
return driver
driver = openDriver()
driver.quit()
print('works')
When i go to this stage i never the "Print" output back in return, except if i remove the def function and just print inside the script which it means something is getting wrong with the def function i guess... Any help will be appreciate it.
Answer
Solution:
You didn't call openDriver function. In your example driver = openDriver() is a part of the function.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the browser (or proxy) sent a request that this server could not understand.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.