from seleniumwire import undetected_chromedriver as uc
wire_options = {
'proxy': {
'https': f'https://{login}:{password}@{ip}:{port}',
}
}
driver = uc.Chrome(seleniumwire_options=wire_options)
self.driver.request_interceptor = interceptor # ставим подмену запросов
def interceptor(request):
"""Подмена css на локальные"""
"""эти файлы не меняем"""
real_urls = (
'styles.css',
)
if str(request.url)[-4:] == '.css':
"""Ищем название файла"""
file = re.search(r"/([^/]+\.css)$", str(request.url)).group(1)
if file not in real_urls:
try:
request.create_response(
status_code=200,
headers={'Content-Type': 'text/css'}, # Optional headers dictionary
body=open(f'fake_files/{file}').read() # Optional body
)
except:
pass
table = driver.find_element(By.ID, "users")
rows = table.find_elements(By.CSS_SELECTOR, "td")
for i in range(len(rows)):
if rows[i].text == "user2":
driver.find_elements(By.PARTIAL_LINK_TEXT, 'Android')[i].click() # берем i-й элемент
import undetected_chromedriver as webdriver # pip install undetected-chromedriver
from selenium.webdriver.common.by import By
browser = webdriver.Chrome()
browser.get('http://youtube.com')
xpath = '/html/body/ytd-app/div[1]/div/ytd-masthead/div[4]/div[3]/div[2]/ytd-button-renderer/yt-button-shape/a/yt-touch-feedback-shape/div/div[2]'
browser.find_element(By.XPATH, xpath).click()