0

I would simply like to get the Open Price of a stock with BeautifulSoup or Selenium is okay but i keep getting just the html tag for it and not the actually price i want

# <div class="tv-fundamental-block__value js-symbol-open">33931.0</div>
import requests
from bs4 import BeautifulSoup

url = requests.get('https://www.tradingview.com/symbols/PEPPERSTONE-US30/')
response = url.content

soup = BeautifulSoup(response, 'html.parser')
# print(soup.prettify())
open = soup.find('div', {'class': 'js-symbol-open'})
print(open)

The 33931.0 is the price id like to see in my terminal but i still dont get it

Using selenium ive only gotten the page i already know where i am getting the data from.

1 Answer 1

1

To extract the text content of the element using BeautifulSoup, use the .text property of the element:

open = soup.find('div', {'class': 'js-symbol-open'}).text
print(open)

In selenium:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://www.tradingview.com/symbols/PEPPERSTONE-US30/')

open_price = driver.find_element_by_css_selector('.js-symbol-open').text
print(open_price)

driver.quit()
Sign up to request clarification or add additional context in comments.

2 Comments

driver.find_element_by_css_selector('.js-symbol-open') is deprecated in selenium4, use newer syntax from selenium.webdriver.common.by import By; driver.find_element(By.CSS_SELECTOR, '.js-symbol-open')
I get this <selenium.webdriver.remote.webelement.WebElement (session="25b611aedf0c9a709503a4c6d6f8814d", element="1ecd6c18-aece-4d8f-94a7-dcb151410b7e")> in the console

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.