I'm new in Python and now I'm trying to scraping the Currency buy/sell rate from BMO website(https://www.bmo.com/home/personal/banking/rates/foreign-exchange) However, all I got was nothing when I tried scraping.
I learned with a sample and wrote a very sample one below with Visual Studio 2019. I could print the paragraph text from those websites however when I changed the xpath to the table cell element path, it returned nothing.
For scraping paragraph text and working:
---------
import requests
from lxml.html import etree
url = 'https://www.bmo.com/home/personal/banking/rates/foreign-exchange'
r=requests.get(url).text
s=etree.HTML(r)
file = s.xpath('//*[@id="main_content"]/p[2]/text()')
print(file)
---------
It working well and output: The rates provided ... bottom of the page as well.
When changed s.xpath back to '//*[@id="ratesTable"]/tbody/tr[2]/td[3]/text()', (I'm trying to scrape selling rate by US dollar), It returned a '[]' with nothing inside. I debugged with 'file' element, it had nothing inside and the length was 0 as well.
Did I do something wrong here? I believe the xpath and url are correctly. And I hope I could get the decimal number 1.2931 (selling rate) in the cell.