Hi guys,
I am trying to write a Python 3 code (using lxml module) to extract some specific data from a webpage.
A sample of the HTML data presented in the webpage is as below.
______________________________________________________________
______________________________________________________________
My code:
______________________________________________________________
I am able to extract the first data (i.e. xx) and store into "var_1". However, I would also need to extract the data that are within the <td> tags of the class "number blue", and store it.
Appreciate it if someone can help to advise on this problem. Thank you.
I am trying to write a Python 3 code (using lxml module) to extract some specific data from a webpage.
A sample of the HTML data presented in the webpage is as below.
______________________________________________________________
1 2 3 4 5 |
<tr> <td><span class = "number blue" >xx< / span>< / td> <td> 001 < / td> <td> 002 < / td> < / tr> |
My code:
1 2 3 4 5 6 7 8 |
from lxml import html import requests tree = html.fromstring(page.content) var_1 = tree.xpath( '//span[@class="number blue"]/text()' ) print (var_1) |
I am able to extract the first data (i.e. xx) and store into "var_1". However, I would also need to extract the data that are within the <td> tags of the class "number blue", and store it.
Appreciate it if someone can help to advise on this problem. Thank you.