1

I'm trying to get a value from a class name but the onlything a could get thill now is a [ ] output. so, what I'm supposed to do in the following code?

from selenium import webdriver
import time

options = webdriver.ChromeOptions()
options.add_argument('lang=pt-br')
driver = webdriver.Chrome(
    executable_path=r'./chromedriver.exe', options=options)
driver.get('https://economia.uol.com.br/cotacoes/cambio/')
time.sleep(5)
dolar = driver.find_elements_by_class_name('currency2')
time.sleep(5)
print(dolar)
1
  • Do you mean get the text of an element with a currency2 classname? Which value are you trying to get? Commented Apr 26, 2020 at 17:37

2 Answers 2

1

You don't need selenium to get that information, try:

import requests

u = "https://api.cotacoes.uol.com/currency/intraday/list/?format=JSON&fields=bidvalue,askvalue,maxbid,minbid,variationbid,variationpercentbid,openbidvalue,date&currency=1"
j = requests.get(u).json()
dolar = j['docs'][0]['bidvalue']
# 5.5916

Demo


Notes:

  • If you need other info, like daily variation (variationpercentbid) search on json the object:

enter image description here

  • Change the currency value at the end of the url for a different currency, for example, currency=5, will give you the EUR values.
Sign up to request clarification or add additional context in comments.

Comments

1

You can use get_attribute to retrieve value of web element, Also in your code you there is no element with class name currency2.

Please find below example :

<input class="field normal" name="currency2" value="5,59" data-audience-click="{&quot;reference&quot;:&quot;ativar-campo-texto&quot;,&quot;component&quot;:&quot;currency-converter&quot;}" xpath="1">

Code to retrieve value:

driver.get('https://economia.uol.com.br/cotacoes/cambio/')
currency = driver.find_element_by_name('currency2')
print currency.get_attribute("value")

Output::

5,59

Comments

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.