Reputation: 56
My html looks like this:
<h3>Current Guide Price <span title="92"> 92
</span></h3>
The info I am trying to get is the 92.
here is another html page where i need to get the same data:
<h3>Current Guide Price <span title="4,161"> 4,161
</span></h3>
I would need to get the 4,161 from this page.
here is the link to the page for reference: http://services.runescape.com/m=itemdb_oldschool/viewitem?obj=1613
What I have tried:
/h3/span[@title="92"]@title
/h3/span[@title="92"]/text()
/div[@class="stats"]/h3/span[@title="4,161"]@title
since the info I need is in the actual span tag, it is hard to grab the data in a dynamic way that I can use for many different pages.
Upvotes: 0
Views: 148
Reputation: 24930
from lxml import html
import requests
baseUrl = 'http://services.runescape.com/m=itemdb_oldschool/viewitem?obj=2355'
page = requests.get(baseUrl)
tree = html.fromstring(page.content)
price = tree.xpath('//h3/span')
price2 = tree.xpath('//h3/span/@title')
for p in price:
print(p.text.strip())
for p2 in price2:
print(p2)
The output is 92
in both cases.
Upvotes: 1