Testing with ChromeDriver
Browse files
app.py
CHANGED
|
@@ -118,26 +118,27 @@ def setup_selenium():
|
|
| 118 |
options.add_argument("--disable-blink-features=AutomationControlled")
|
| 119 |
options.add_argument("--disable-notifications")
|
| 120 |
options.add_argument("--remote-debugging-port=9222")
|
| 121 |
-
|
| 122 |
# Disable automation flag
|
| 123 |
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
| 124 |
options.add_experimental_option("useAutomationExtension", False)
|
| 125 |
-
|
| 126 |
# Mimic a real browser's user agent
|
| 127 |
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")
|
| 128 |
|
| 129 |
logger.info("Verifying ChromeDriver...")
|
| 130 |
verifying_chromedriver = verify_chromedriver()
|
| 131 |
logger.info(f"ChromeDriver verification: {verifying_chromedriver}")
|
| 132 |
-
|
| 133 |
chromedriver_path = "/usr/local/bin/chromedriver"
|
| 134 |
os.chmod(chromedriver_path, 0o755) # Make sure it's executable
|
| 135 |
-
|
|
|
|
| 136 |
service = create_service()
|
| 137 |
logger.info("Service created")
|
| 138 |
|
| 139 |
verify_critical_path()
|
| 140 |
-
|
| 141 |
try:
|
| 142 |
logger.info("Attempting Chrome initialization...")
|
| 143 |
driver = webdriver.Chrome(
|
|
@@ -146,7 +147,7 @@ def setup_selenium():
|
|
| 146 |
)
|
| 147 |
logger.info("Successfully initialized Chrome driver!")
|
| 148 |
return driver
|
| 149 |
-
|
| 150 |
except Exception as e:
|
| 151 |
logger.error(f"Initialization failed completely: {str(e)}")
|
| 152 |
try:
|
|
@@ -219,7 +220,7 @@ def fetch_sentences(input_text):
|
|
| 219 |
|
| 220 |
rows = table.find_elements(By.TAG_NAME, "tr")
|
| 221 |
print(len(rows))
|
| 222 |
-
|
| 223 |
for row in rows:
|
| 224 |
row_cells = row.find_elements(By.TAG_NAME, "td")
|
| 225 |
generated_sentences.append([r.text for r in row_cells])
|
|
|
|
| 118 |
options.add_argument("--disable-blink-features=AutomationControlled")
|
| 119 |
options.add_argument("--disable-notifications")
|
| 120 |
options.add_argument("--remote-debugging-port=9222")
|
| 121 |
+
|
| 122 |
# Disable automation flag
|
| 123 |
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
| 124 |
options.add_experimental_option("useAutomationExtension", False)
|
| 125 |
+
|
| 126 |
# Mimic a real browser's user agent
|
| 127 |
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")
|
| 128 |
|
| 129 |
logger.info("Verifying ChromeDriver...")
|
| 130 |
verifying_chromedriver = verify_chromedriver()
|
| 131 |
logger.info(f"ChromeDriver verification: {verifying_chromedriver}")
|
| 132 |
+
|
| 133 |
chromedriver_path = "/usr/local/bin/chromedriver"
|
| 134 |
os.chmod(chromedriver_path, 0o755) # Make sure it's executable
|
| 135 |
+
logger.info(f"Setting executable permission for {chromedriver_path}")
|
| 136 |
+
|
| 137 |
service = create_service()
|
| 138 |
logger.info("Service created")
|
| 139 |
|
| 140 |
verify_critical_path()
|
| 141 |
+
|
| 142 |
try:
|
| 143 |
logger.info("Attempting Chrome initialization...")
|
| 144 |
driver = webdriver.Chrome(
|
|
|
|
| 147 |
)
|
| 148 |
logger.info("Successfully initialized Chrome driver!")
|
| 149 |
return driver
|
| 150 |
+
|
| 151 |
except Exception as e:
|
| 152 |
logger.error(f"Initialization failed completely: {str(e)}")
|
| 153 |
try:
|
|
|
|
| 220 |
|
| 221 |
rows = table.find_elements(By.TAG_NAME, "tr")
|
| 222 |
print(len(rows))
|
| 223 |
+
|
| 224 |
for row in rows:
|
| 225 |
row_cells = row.find_elements(By.TAG_NAME, "td")
|
| 226 |
generated_sentences.append([r.text for r in row_cells])
|