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.
______________________________________________________________
<tr> <td><span class="number blue">xx</span></td> <td>001</td> <td>002</td> </tr>______________________________________________________________
My code:
from lxml import html import requests page = requests.get("http://some_website.aspx") 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.