I need to pull the APR from Yahoo Finance using Python. I was trying to follow a basic example found here , but I keep returning an empty list. This is the code that I am using:
import requests
from lxml import html
page = requests.get('http://finance.yahoo.com/rates/')
tree = html.fromstring(page.text)
interest_rates = tree.xpath('//div[@class="apr"]/text()')
print('Interest Rates: ', interest_rates)
It seems that the XPath I am using is incorrect. What would be the correct Xpath?
Edit:
I used the firebug plugin and to copy the xpath of the data I wanted. It gave me the following xpath:
/html/body/form/div[4]/table/tbody/tr[2]/td[2]/div[1]
after rerunning my code with the updated xpath I am still returning an empty list. Is there something else I need to include in my Xpath?
Edit2
import requests
from lxml import html
page = requests.get('http://finance.yahoo.com/rates/')
tree = html.fromstring(page.text)
interest_rate = tree.xpath('/html/body/form/div[4]/table/tbody/tr[2]/td[2]/div[1]/text()')
print('One interest rate is: ', interest_rate)