Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

wanted to extract table info from the webpage

i just wanted to scrape the Countries in the world by population table from below table

"https://www.worldometers.info/world-population/population-by-country/"

sample data
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can grab the desired table data using pandas

import pandas as pd 
import requests

headers={"User-Agent":"mozilla/5.0"}
url='https://www.worldometers.info/world-population/population-by-country/'
red=requests.get(url,headers=headers).text

df = pd.read_html(red)[0]
print(df)

Output:

0      1                   China         1439323776  ...       38         61 %      18.47 
%
1      2                   India         1380004385  ...       28         35 %      17.70 
%
2      3           United States          331002651  ...       38         83 %       4.25 
%
3      4               Indonesia          273523615  ...       30         56 %       3.51 
%
4      5                Pakistan          220892340  ...       23         35 %       2.83 
%
..   ...                     ...                ...  ...      ...          ...          ...
230  231              Montserrat               4992  ...     N.A.         10 %       0.00 
%
231  232        Falkland Islands               3480  ...     N.A.         66 %       0.00 
%
232  233                    Niue               1626  ...     N.A.         46 %       0.00 
%
233  234                 Tokelau               1357  ...     N.A.          0 %       0.00 
%
234  235                Holy See                801  ...     N.A.         N.A.       0.00 
%

[235 rows x 12 columns]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading