Мой вебскреб выглядит так:< /p>
Код: Выделить всё
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
url = "https://www.wsj.com/market-data/stocks/us"
driver.get(url)
time.sleep(10)
try:
element = driver.find_element(By.XPATH, "/html/body/div/div/div/div/div[1]/div[2]/div/div[2]/table/tbody[1]/tr/td[2]")
data = element.text
print(f"Found data: {data}")
except Exception as e:
print(f"Error: {e}")
driver.quit()
Код: Выделить всё
element = driver.find_element(By.XPATH, “/html/body/div/div/div/div/div[1]/div[2]/div/div[2]/table/tbody[1]/tr/td[2]”)
Код: Выделить всё
Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/div/div/div/div[1]/div[2]/div/div[2]/table/tbody[1]/tr/td[2]"}
(Session info: chrome=131.0.6778.205); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Код: Выделить всё
element = driver.find_element(By.XPATH, "//body")
Увеличение времени ожидания time.sleep(10) ничего не изменило.
Почему я Мне не показывают все тело?
Подробнее здесь: https://stackoverflow.com/questions/793 ... re-website