Aug-24-2018, 02:13 AM
(Aug-23-2018, 07:01 PM)snippsat Wrote: Removetext()
from Xpath,can use.text
from lxml.
Now can also take out.attrib
from CSS class.
from lxml import etree # Simulate a web page html = '''\ <html> <head> <title>foo</title> </head> <body> <tr> <td><span class="number blue">xx</span></td> <td>001</td> <td>002</td> </tr>> </body> </html>''' tree = etree.fromstring(html) span_tag = tree.xpath("//span[@class='number blue']") print(span_tag[0].text) print(span_tag[0].attrib.get('class'))
Output:xx number blue
Thanks for your reply. However, I want to get the two values (i.e. 001 and 002) within the <td> tags. They all belong to the same span class (i.e. number blue).
Any idea how to get these values neatly?