I am trying to fetch data from a tabular table. I want to get all data from the table but for some reason I can't even get the title to display. Can someone give me some pointers as to what I'm doing wrong here? Thanks
from lxml import html
import requests
page = requests.get("https://www150.statcan.gc.ca/t1/tbl1/en/tv.action?pid=1710000501")
tree = html.fromstring(page.content)
title = tree.xpath('//*[@id="1_1"]/text()')
print("title", title)
After making some tests, you need to pass a cookie value in the header of your request. Otherwise you won't be able to get the page. Code :
Output (Canada, and the population estimates for both sexes in 2015) :