from lxml import html
import requests
url = 'https://www.bloomberg.com/quote/SPX:IND'
page = requests.get(url)
tree = html.fromstring(page.content)
num = tree.xpath('//*[@id="root"]/div/div/section[2]/div[1]/div/section[1]/section/section[2]/section/div[1]/span[1]/text()')
print (num)
this is the code I have written. I'm trying to get the string 2758.82,from this. but what I get is.
[]
I copied the xpath for that section from the website. I have seen similar questions here, but they didn't help. Is something wrong with my code?
requests.get(url,headers={"User-Agent":"Mozilla/5.0"})to make your scraper more like a human.<div style="display:inline" data-dobid="dfn"><span>some text.</span></div>and what if<span>has some attributes too?