<div id="yandex_rtb_R-A-2602770-3"><div></div></div>
, а что находится внутри - он не видит. В том числе там ничего нету и в driver.page_source.Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/lev/Desktop/PY/ad_viewer/.venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 404, in execute_script
return self.execute(command, {"script": script, "args": converted_args})["value"]
File "/Users/lev/Desktop/PY/ad_viewer/.venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 344, in execute
self.error_handler.check_response(response)
File "/Users/lev/Desktop/PY/ad_viewer/.venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read properties of null (reading 'querySelector')
</>
shadow_host = driver.find_element_by_css_selector('#shadow_host')
shadow_root_dict = driver.execute_script('return arguments[0].shadowRoot', shadow_host)
shadow_root_id = shadow_root_dict['shadow-6066-11e4-a52e-4f735466cecf']
shadow_root = WebElement(driver, shadow_root_id, w3c=True)
shadow_content = shadow_root.find_element_by_css_selector('#shadow_content')
shadow_host = driver.find_element(By.CSS_SELECTOR, '#shadow_host')
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/lev/Desktop/PY/ad_viewer/.venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 738, in find_element
return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
File "/Users/lev/Desktop/PY/ad_viewer/.venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 344, in execute
self.error_handler.check_response(response)
File "/Users/lev/Desktop/PY/ad_viewer/.venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#shadow_host"}
(Session info: chrome=117.0.5938.132); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
print("Браузер запускается, подождите немного")
try:
driver.get(url="https://podoq.ru")
sleep(7)
for _ in range(1, 9):
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
sleep(1)
sleep(4)
print(link)
except Exception as e:
print(e)
finally:
driver.quit()
#shadow-root
expression = "document.querySelector('#yandex_rtb_R-A-2602770-3').shadowRoot";
{"result":{"subtype":"null","type":"object","value":null}}
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
print("Браузер запускается, подождите немного")
try:
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {'source': """
Element.prototype._attachShadow = Element.prototype.attachShadow;
Element.prototype.attachShadow = function () {
return this._attachShadow( { mode: "open" } );
};
"""})
driver.get(url="https://podoq.ru")
sleep(3)
for _ in range(1, 7):
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
sleep(1)
shadow_host=driver.find_element(By.XPATH,'//footer//div[contains(@id,"yandex_rtb")]/div')
shadow_root_a_els = driver.execute_script('return arguments[0].shadowRoot.querySelectorAll("a");', shadow_host)
for shadow_root_a_el in shadow_root_a_els:
print(f"{shadow_root_a_el.text} {shadow_root_a_el.get_attribute('href')}")
except Exception as e:
print(e)
raise
finally:
driver.quit()
Браузер запускается, подождите немного
https://yandex.ru/an/count/WU0ejI_zOoVX2LcN0PKE06EPOIO...
karo.spb.ru https://yandex.ru/an/count/WU0ejI_zOoVX2LcN0PKE06EPOIOQb...
Монтгомери. Энн из Авонлеи. Английский без сокращений https://yandex.ru/an/count/WU0ejI_zOoVX2LcN0PKE06EPOIOQb....
Доставка по всей России • Напрямую от издательства • Есть электронная вер...