Search code examples
pythonseleniumbeautifulsouphtml-table

Use Python to scrape a table from a website


I am here to ask for help on how to write a program to capture the value 10,599 from below site.

https://www.immd.gov.hk/eng/stat_20221001.html

The element that contains the value that I want to capture is as follows.

<td class="hRight" headers="Total_Departure" data-label="Total">10,599</td>

Thanks for the help in advance!

I am fairly new to python and recently I have just been enlightened that I can use selenium or bs4 to scrape a website onto a table. After researching many websites and watching countless youtube videos, my effort is still in vain.


Solution

  • You can use this locator:

    .//td[@headers='Control_Point' and text()='Total']//parent::tr//td[@headers='Total_Departure']