Reputation: 25
I'm doing we scraping and I have an issue with a web page that is given me empty values (I'm looking for values 59.5 and 61) This is the code
import requests
import lxml
from bs4 import BeautifulSoup
r = requests.get("https://dolarbalanz.com")
soup = BeautifulSoup(r.text, 'lxml')
info = soup.find_all("div", attrs={"class": "marco-dolarcobrar"})
print(info)
The output is a string that is the div class that should contain the values that I need. But the specific part for the values is empty ('': '')
. What is the problem? Is this because the contents are dynamic and I should use selenium? if that is the case, how is the best way to do it from my code?
Thanks!
Eric
Upvotes: 2
Views: 105
Reputation: 33384
This data is rendered by javascripts. However if you go to nextwork tab you will get below API which returns data in json format.
import requests
r = requests.get("https://dolarbalanz.com/api/dolarBalanz").json()
print(r['precioCompraVenta'][0]['precioventa'])
print(r['precioCompraVenta'][0]['preciocompra'])
Output:
61
59.5
NetwrokTab:
Upvotes: 1