Мне нужно войти на веб-сайт (это открытый веб-сайт, любой может создать имя пользователя и пароль для входа), прокрутить вниз, нажать «рак простаты», а затем просмотреть весь статус фонда (заблокирован или разблокирован). Я использую селен для очистки веб-страниц.
Это мой код:
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
# Set up Chrome options for headless mode
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
# Set up the WebDriver
service = Service('/usr/local/bin/chromedriver') # Update with the path to your ChromeDriver
driver = webdriver.Chrome(service=service, options=chrome_options)
# Open the website
HOME_PAGE = 'https://fundfinder.panfoundation.org'
driver.get(HOME_PAGE)
# Wait for the page to load
time.sleep(2)
# Find the username and password fields and log in
username_field = driver.find_element(By.NAME, 'email')
password_field = driver.find_element(By.NAME, 'phrase')
username_field.send_keys('Your_UserName') # Replace with your username
password_field.send_keys('Your_Password') # Replace with your password
password_field.send_keys(Keys.RETURN) # Press Enter to log in
Код: Выделить всё
data_element = driver.find_element(By.XPATH, '//div[@class="data"]')
- нажмите ссылку «Рак простаты» после входа в систему.
- получите статус 5-го фонда (в настоящее время все заблокированы - значит недоступны)
Подробнее здесь: https://stackoverflow.com/questions/798 ... g-selenium
Мобильная версия