Вручную можно сделать через настройку "Разрешить сайтам показывать небезопасный контент" с указанием ссылки на web ui, но не понимаю как это можно реализовать в коде.
появляется ошибка selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found. Как от нее избавиться?
# EC.presence_of_element_located((By.CSS_SELECTOR, "product-slider__img js-product-current-img"))
EC.presence_of_element_located((By.CSS_SELECTOR, ".product-slider__img.js-product-current-img"))
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.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
options = Options()
service = Service(r'D:\project\chromedriver-130.0.6723.93.exe')
driver = webdriver.Chrome(service=service, options=options)
url = 'https://superstep.ru/product/NCFSW0W288YW_GRA/#colorGRA'
driver.get(url)
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".product-slider__img.js-product-current-img"))
)
page_html = driver.page_source
print(page_html)
except TimeoutException:
print("Элемент не найден")
finally:
print('Программа завершена')
driver.quit()
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
options = Options()
service = Service(r'D:\project\geckodriver.exe')
driver = webdriver.Firefox(service=service, options=options)
url = 'https://superstep.ru/product/NCFSW0W288YW_GRA/#colorGRA'
driver.get(url)
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".product-slider__img.js-product-current-img"))
)
page_html = driver.page_source
print(page_html)
except TimeoutException:
print("Элемент не найден")
finally:
print('Программа завершена')
driver.quit()
Возможно ли с помощью selenium создать такой скрипт, что:
$ curl https://codeforces.com/
<!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge">
данный код не работает
# driver.find_element("xpath", "//input[@id='LinkDa']" ).click
driver.find_element("xpath", "//input[@id='LinkDa']" ).click()
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get('https://autoins.ru/osago/raschet-stoimosti-osago/proverit-kbm/')
# Debug
time.sleep(10)
checkbox = driver.find_element(By.XPATH, '//label[@for="linkDa"]')
checkbox.click()
# Debug
time.sleep(10)
button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "btnDa"))
)
button.click()
# Debug
time.sleep(10)
driver.quit()
# h2= g.find_element(By.XPATH, '//h2').text
h2 = g.find_element(By.XPATH, './/h2').text
Как в selenium открыть селектор на JS?
Но далее чтобы получить номер уже зареганым, просит подтвердить капчей.
Есть ли возможность сделать движения похожими на человеческие
или еще лучше, как-то сделать имитацию регистрации и получить номер
Как сделать так, чтобы при запуске скрипта, соответственно, переходе по ссылке, каждый раз не открывалась новая сессия?
import os
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# ChromeDriver path (https://sites.google.com/chromium.org/driver/downloads)
chromedriver_path = r'C:\project\chromedriver.exe'
# Chrome profile path
profile_dir = r'C:\project\chrome-profiles\1'
# Create chrome profile (run in console):
# $ chrome C:\project\chrome-profiles\1
#
# or
#
# auto create chrome profile (if need)
if not os.path.exists(profile_dir):
os.makedirs(profile_dir)
# Using chrome profile
options = webdriver.ChromeOptions()
options.add_argument(f'--user-data-dir={profile_dir}')
# Init
service = Service(executable_path=chromedriver_path)
driver = webdriver.Chrome(service=service, options=options)
# Open website
driver.get('https://maps.yandex.ru/')
# Delay and close driver
time.sleep(10)
driver.quit()
import time
from fake_useragent import UserAgent
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
option = webdriver.ChromeOptions()
ua = UserAgent()
option.add_argument(f'user-agent={ua.random}')
option.add_argument("--disable-infobars")
s = Service(executable_path=r"C:\Python Scripts\валид\Steam Number\chromedriver.exe")
driver = webdriver.Chrome(options=option, service=s)
driver.maximize_window()
driver.get('https://help.steampowered.com/en/wizard/HelpWithLoginInfo?issueid=406')
# iframe
iframe = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div[7]/div[2]/div[2]/div/div[2]/div[1]/div[3]/form/div[3]/div[1]/div/div/div/iframe'))
)
# switch to iframe context
driver.switch_to.frame(iframe)
element_to_click = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '/html/body/div[2]/div[3]'))
)
element_to_click.click()
# switch to default context
driver.switch_to.default_content()
time.sleep(10)
driver.quit()
Посоветуйте ресурсы
мне бы хотелось максимально узнать как водить курсором с помощью этой бибилиотеки как человек