1
votes

Trying to scrape pricing data from this page: https://www.bloomberg.com/quote/EQUPEUI:LN

Using the following XPATH: /html/body[@class='default-layout markets-section-front']/div[@class='container']/main[@id='content']/div/div[@class='quote-page module']/div[@class='basic-quote']/div/div[@class='price-container up']/div[@class='price']

Not working... I am stuck and would really appreciate your help.

2

2 Answers

0
votes

You are so very close. You are just missing /text() at the end of your XPath expression.

/html/body[@class='default-layout markets-section-front']/div[@class='container']/main[@id='content']/div/div[@class='quote-page module']/div[@class='basic-quote']/div/div[@class='price-container up']/div[@class='price']/text()

This works in python:

from lxml import html
import requests

req = requests.get('https://www.bloomberg.com/quote/EQUPEUI:LN')
tree = html.fromstring(req.content)

price = tree.xpath("//div[@class='price-container up']/div[@class='price']/text()")[0]

print "The price is:", price

Note you can greatly simplify the XPath expression by not starting from the root HTML tag.

0
votes

You can also use following relative xpath

//main[@id='content']//div[@class='price']

Locate the element with above xpath and use getText() method to get text of the element.