1

I need to get some numbers from this website

http://www.preciodolar.com/

But the data I need, takes a little time to load and shows a message of 'wait' until it completely loads.

I used find all and some regular expressions to get the data I need, but when I execute, python gives me the 'wait' message that appears before the data loads.

Is there a way to make python 'wait' until all data is loaded? my code looks like this,

import urllib.request
from re import findall

def divisas():

pag = urllib.request.urlopen('http://www.preciodolar.com/')
html = str(pag.read())
brasil = findall('<td class="usdbrl_buy">(.*?)</td>',html)
return brasil
akash
  • 22,664
  • 11
  • 59
  • 87
user3435341
  • 51
  • 1
  • 1
  • 6

2 Answers2

0

This is because the page is generated with JavaScript. You're getting the full HTML, but the JavaScript handles changing the DOM and showing the information. You have two options:

  1. Try and interpret the JavaScript (not easy). There are a lot of questions about this in stack overflow already.
  2. Find the URL the page is hitting with AJAX to get the actual data and use that.

It really just depends on what you need the page for. It looks like you are trying to parse the data and so the second option allows you to make a single request to just get the raw data.

Community
  • 1
  • 1
hazmat
  • 640
  • 5
  • 12
0

You should find ajax request or jsonp request instead. In this case , it's jsonp: http://api.preciodolar.com/api/crossdata.php?callback=jQuery1112024555979575961828_1442466073980&_=1442466073981

mcbill
  • 367
  • 3
  • 12