This commit is contained in:
Yeet 2024-09-24 21:38:29 +02:00
parent c851b9d7e2
commit d63a39b49a
3 changed files with 15 additions and 4 deletions

View File

@ -16,10 +16,10 @@ RUN apt-get update && \
wget \ wget \
curl \ curl \
unzip \ unzip \
chromium-driver \
build-essential \ build-essential \
libsqlite3-dev \ libsqlite3-dev \
sqlite3 \ sqlite3 \
chromium \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
@ -27,10 +27,11 @@ RUN apt-get update && \
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Set up Chrome WebDriver for Selenium # Set up Chrome WebDriver for Selenium
RUN wget -q -O /app/chromedriver.zip https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip && \ RUN wget -q -O /app/chromedriver.zip https://storage.googleapis.com/chrome-for-testing-public/129.0.6668.70/linux64/chromedriver-linux64.zip && \
unzip /app/chromedriver.zip && \ unzip /app/chromedriver.zip && \
mv /app/chromedriver-linux64/chromedriver /app && \
chmod +x /app/chromedriver && \ chmod +x /app/chromedriver && \
rm /app/chromedriver.zip rm -rf /app/chromedriver.zip /app/chromedriver-linux64
# Set environment variables for Chrome and ChromeDriver # Set environment variables for Chrome and ChromeDriver
ENV PATH=/app:$PATH ENV PATH=/app:$PATH

View File

@ -8,3 +8,4 @@ google-auth==2.34.0
google-auth-httplib2==0.2.0 google-auth-httplib2==0.2.0
google-auth-oauthlib==1.2.1 google-auth-oauthlib==1.2.1
googleapis-common-protos==1.65.0 googleapis-common-protos==1.65.0
webdriver-manager==4.0.2

View File

@ -8,6 +8,10 @@ import time
import requests import requests
import config import config
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
service = Service(ChromeDriverManager().install())
class XClient: class XClient:
@ -28,16 +32,19 @@ class XClient:
def fetch_access_token(self): def fetch_access_token(self):
# Set up the WebDriver (make sure to use the correct path for your WebDriver) # Set up the WebDriver (make sure to use the correct path for your WebDriver)
print("starting chromedriver")
options = webdriver.ChromeOptions() options = webdriver.ChromeOptions()
options.add_argument("--headless=new") options.add_argument("--headless=new")
options.add_argument("--no-sandbox") options.add_argument("--no-sandbox")
service = Service(executable_path=config.CHROMEDRIVER_PATH) print("started chromedriver")
driver = webdriver.Chrome(options=options, service=service) driver = webdriver.Chrome(options=options, service=service)
driver.get("https://x.tudelft.nl") driver.get("https://x.tudelft.nl")
print("Check1")
button = WebDriverWait(driver, 30).until( button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable( EC.element_to_be_clickable(
(By.XPATH, "//span[contains(text(), 'TUDelft')]") (By.XPATH, "//span[contains(text(), 'TUDelft')]")
@ -53,6 +60,8 @@ class XClient:
) )
) )
) )
print("Check2")
button.click() button.click()
# Input the username # Input the username