Matthew
Matthew

Reputation: 13

Xpath not getting any data

I am trying to retrieve data from this rates website but It just cant get anything. I have tried this same format for a different website and it works fine so I'm not sure what is going on here.

import requests
from requests_html import HTMLSession
#get usd to gbp rate
session = HTMLSession()
response = session.get('https://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=GBP')
rate = response.html.xpath('//span[@class="converterresult-toAmount"]/*')
print('USD to GBP Rate:',rate)

#(output): USD to GBP Rate: []

Upvotes: 0

Views: 109

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66723

The HTML content returned from that URL is minimal, and does not contain the content you are attempting to target with XPath.

It appears that the JavaScript evaluated will render the content you are trying to scrape with react. In the HTML that is returned, there is a comment:

<!-- WARNING: Automated extraction of rates is prohibited under the Terms of Use. -->

So, I don't think they want you extracting data from the pages with scripts and automation.

Upvotes: 1

Related Questions