|
|
Reading https://en.wikipedia.org/wiki/Template:COVID-19_pandemic_data
Locating around /<span class="flagicon">/
At 2
Splitting at /\"\>|\<\/a\>/
Take 2 as country At 4
Splitting at /">|<\/td>/
Take 1 as cases At 6
Splitting at /">/
Taking 1 as deaths Cleaning up /^[^0-9]+$/
Replace with NA
Output tsv+header
|
|
use LWP 5.64;
my $browser = LWP::UserAgent->new;
$browser->agent("Mozilla/5.0");
my $res = $browser->get("https://en.wikipedia.org/wiki/Template:COVID-19_pandemic_data");
my @lines = split /\n/, $res->decoded_content;
my $processing = 0;
print "country\tcases\tdeaths\n";
for (my $a = 0; $a < @lines; $a++) {
if ($lines[$a] =~ /\<span class="flagicon"\>/) {
my @array1 = split /\"\>|\<\/a\>/, $lines[$a+2];
print $array1[2]."\t";
my @array2 = split /\"\>|\<\/td\>/, $lines[$a+4];
print $array2[1]."\t";
my @array3 = split /\"\>/, $lines[$a+6];
$array3[1] =~ s/^[^0-9]$/NA/;
print $array3[1]."\n";
}
}
|
|
country | cases | deaths | | European Union | 186,339,025 | 1,266,463 | | United States | 103,436,829 | 1,210,707 | | China | 99,381,579 | 122,391 | | India | 45,044,549 | 533,661 | | France | 39,010,797 | 168,134 | | Germany | 38,437,756 | 174,979 | | Brazil | 37,511,921 | 702,116 | | South Korea | 34,571,873 | 35,934 | | Japan | 33,803,572 | 74,694 | | Italy | 26,826,486 | 197,542 | | United Kingdom | 25,023,567 | 232,112 | | Russia | 24,799,330 | 403,979 | | Turkey | 17,004,712 | 101,419 | | Spain | 13,980,340 | 121,852 | | Australia | 11,861,161 | 25,236 | | Vietnam | 11,624,000 | 43,206 | | Argentina | 10,110,587 | 130,734 | | Taiwan | 9,970,937 | 17,672 | | Netherlands | 8,635,647 | 22,986 | | Iran | 7,627,863 | 146,837 | | Mexico | 7,622,513 | 334,818 | | Indonesia | 6,830,081 | 162,059 | | Poland | 6,769,273 | 120,973 | | Colombia | 6,394,655 | 142,727 | | Austria | 6,083,011 | 22,534 | | Greece | 5,752,314 | 39,872 | | Portugal | 5,670,595 | 29,078 | | Ukraine | 5,541,114 | 109,925 | | Chile | 5,409,945 | 64,497 | | Malaysia | 5,325,669 | 37,351 | | Belgium | 4,893,750 | 34,339 | | Israel | 4,841,558 | 12,707 | | Czech Republic | 4,825,331 | 43,772 | | Canada | 4,819,055 | 55,282 | | Thailand | 4,808,454 | 34,741 | | Peru | 4,528,708 | 220,994 | | Switzerland | 4,475,319 | 14,170 | | Philippines | 4,173,631 | 66,864 | | South Africa | 4,072,857 | 102,595 | | Romania | 3,567,674 | 68,949 | | Denmark | 3,445,401 | 10,012 | | Singapore | 3,006,155 | 2,024 | | Hong Kong | 2,876,106 | 13,466 | | Sweden | 2,771,104 | 28,365 | | New Zealand | 2,663,381 | 4,497 | | Serbia | 2,583,470 | 18,057 | | Iraq | 2,465,545 | 25,375 | | Hungary | 2,237,414 | 49,117 | | Bangladesh | 2,051,534 | 29,499 | | Slovakia | 1,885,566 | 21,266 | | Georgia | 1,864,383 | 17,151 | | Republic of Ireland | 1,752,048 | 9,914 | | Jordan | 1,746,997 | 14,122 | | Pakistan | 1,580,631 | 30,656 | | Norway | 1,531,861 | 5,732 | | Kazakhstan | 1,504,370 | 19,072 | | Finland | 1,499,712 | 11,466 | | Lithuania | 1,419,418 | 9,868 | | Slovenia | 1,361,219 | 9,914 | | Croatia | 1,352,684 | 18,781 | | Bulgaria | 1,339,011 | 38,771 | | Morocco | 1,279,115 | 16,305 | | Puerto Rico | 1,252,713 | 5,938 | | Guatemala | 1,250,394 | 20,203 | | Lebanon | 1,239,904 | 10,947 | | Costa Rica | 1,235,825 | 9,374 | | Bolivia | 1,212,156 | 22,387 | | Tunisia | 1,153,361 | 29,423 | | Cuba | 1,113,662 | 8,530 | | Ecuador | 1,078,897 | 36,055 | | United Arab Emirates | 1,067,030 | 2,349 | | Panama | 1,045,054 | 8,764 | | Uruguay | 1,042,511 | 7,693 | | Mongolia | 1,011,489 | 2,136 | | Nepal | 1,003,450 | 12,031 | | Belarus | 994,045 | 7,118 | | Latvia | 977,765 | 7,475 | | Saudi Arabia | 841,469 | 9,646 | | Azerbaijan | 836,492 | 10,353 | | Paraguay | 735,759 | 19,880 | | Cyprus | 710,328 | 1,497 | | Palestine | 703,228 | 5,708 | | Bahrain | 696,614 | 1,536 | | Sri Lanka | 672,812 | 16,907 | | Kuwait | 667,290 | 2,570 | | Dominican Republic | 661,103 | 4,384 | | Moldova | 650,867 | 12,283 | | Myanmar | 643,239 | 19,494 | | Estonia | 613,956 | 2,998 | | Venezuela | 552,695 | 5,856 | | Egypt | 516,023 | 24,830 | | Qatar | 514,524 | 690 | | Libya | 507,269 | 6,437 | | Ethiopia | 501,258 | 7,574 | | Réunion | 494,595 | 921 | | Honduras | 472,911 | 11,114 | | Armenia | 453,089 | 8,779 | | Bosnia and Herzegovina | 404,120 | 16,404 | | Oman | 399,449 | 4,628 | | Luxembourg | 396,839 | 1,000 | | North Macedonia | 352,060 | 9,990 | | Brunei | 350,292 | 182 | | Zambia | 349,892 | 4,078 | | Kenya | 344,113 | 5,689 | | Albania | 337,196 | 3,608 | | Botswana | 330,696 | 2,801 | | Mauritius | 329,686 | 1,074 | | Kosovo | 274,279 | 3,212 | | Algeria | 272,189 | 6,881 | | Nigeria | 267,190 | 3,155 | | Zimbabwe | 266,399 | 5,740 | | Montenegro | 251,280 | 2,654 | | Afghanistan | 235,214 | 7,998 | | Mozambique | 233,876 | 2,252 | | Martinique | 230,354 | 1,104 | | Laos | 219,060 | 671 | | Iceland | 210,743 | 186 | | Guadeloupe | 203,235 | 1,021 | | El Salvador | 201,967 | 4,230 | | Trinidad and Tobago | 191,496 | 4,390 | | Maldives | 186,694 | 316 | | Uzbekistan | 175,082 | 1,016 | | Namibia | 172,556 | 4,110 | | Ghana | 172,331 | 1,463 | | Uganda | 172,161 | 3,632 | | Jamaica | 157,349 | 3,621 | | Cambodia | 139,326 | 3,056 | | Rwanda | 133,266 | 1,468 | | Cameroon | 125,279 | 1,974 | | Malta | 123,586 | 1,009 | | Barbados | 108,837 | 593 | | Angola | 107,487 | 1,937 | | Democratic Republic of the Congo | 100,990 | 1,474 | | French Guiana | 98,041 | 413 | | Senegal | 89,318 | 1,972 | | Malawi | 89,168 | 2,686 | | Kyrgyzstan | 88,953 | 1,024 | | Ivory Coast | 88,457 | 835 | | Suriname | 82,506 | 1,406 | | New Caledonia | 80,203 | 314 | | French Polynesia | 79,451 | 650 | | Eswatini | 75,356 | 1,427 | | Guyana | 74,492 | 1,302 | | Belize | 71,430 | 688 | | Fiji | 69,047 | 885 | | Madagascar | 68,598 | 1,428 | | Jersey | 66,391 | 161 | | Cabo Verde | 64,474 | 417 | | Sudan | 63,993 | 5,046 | | Mauritania | 63,879 | 997 | | Bhutan | 62,697 | 21 | | Syria | 57,423 | 3,163 | | Burundi | 54,569 | 15 | | Guam | 52,287 | 419 | | Seychelles | 51,899 | 172 | | Gabon | 49,056 | 307 | | Andorra | 48,015 | 159 | | Papua New Guinea | 46,864 | 670 | | Curaçao | 45,883 | 305 | | Aruba | 44,224 | 292 | | Tanzania | 43,365 | 846 | | Mayotte | 42,027 | 187 | | Togo | 39,537 | 290 | | Bahamas | 39,127 | 849 | | Guinea | 38,582 | 468 | | Isle of Man | 38,008 | 116 | | Lesotho | 36,138 | 709 | | Guernsey | 35,326 | 67 | | Haiti | 34,764 | 860 | | Faroe Islands | 34,658 | 28 | | Mali | 33,180 | 743 | | Federated States of Micronesia | 31,765 | 65 | | Cayman Islands | 31,472 | 37 | | Saint Lucia | 30,231 | 410 | | Benin | 28,036 | 163 | | Somalia | 27,334 | 1,361 | | Solomon Islands | 25,954 | 199 | | United States Virgin Islands | 25,389 | 132 | | San Marino | 25,292 | 126 | | Republic of the Congo | 25,234 | 389 | | Timor-Leste | 23,460 | 138 | | Burkina Faso | 22,165 | 400 | | Liechtenstein | 21,613 | 89 | | Gibraltar | 20,550 | 113 | | Grenada | 19,693 | 238 | | Bermuda | 18,860 | 165 | | South Sudan | 18,855 | 147 | | Tajikistan | 17,786 | 125 | | Monaco | 17,181 | 67 | | Equatorial Guinea | 17,130 | 183 | | Samoa | 17,057 | 31 | | Tonga | 16,992 | 13 | | Marshall Islands | 16,297 | 17 | | Nicaragua | 16,197 | 245 | | Dominica | 16,047 | 74 | | Djibouti | 15,690 | 189 | | Central African Republic | 15,443 | 113 | | Northern Mariana Islands | 14,985 | 41 | | Gambia | 12,627 | 372 | | Collectivity of Saint Martin | 12,324 | 46 | | Vanuatu | 12,019 | 14 | | Greenland | 11,971 | 21 | | Yemen | 11,945 | 2,159 | | Caribbean Netherlands | 11,922 | 41 | | Sint Maarten | 11,051 | 92 | | Eritrea | 10,189 | 103 | | Saint Vincent and the Grenadines | 9,674 | 124 | | Guinea-Bissau | 9,614 | 177 | | Niger | 9,528 | 315 | | Comoros | 9,109 | 161 | | Antigua and Barbuda | 9,106 | 146 | | American Samoa | 8,359 | 34 | | Liberia | 8,090 | 294 | | Sierra Leone | 7,985 | 126 | | Chad | 7,702 | 194 | | British Virgin Islands | 7,643 | 64 | | Cook Islands | 7,375 | 2 | | Turks and Caicos Islands | 6,833 | 40 | | Sao Tome and Principe | 6,771 | 80 | | Saint Kitts and Nevis | 6,607 | 46 | | Palau | 6,372 | 10 | | Saint Barthélemy | 5,507 | 5 | | Nauru | 5,393 | 1 | | Kiribati | 5,085 | 24 | | Anguilla | 3,904 | 12 | | Wallis and Futuna | 3,760 | 9 | | Macau | 3,514 | 121 | | Saint Pierre and Miquelon | 3,426 | 2 | | Tuvalu | 2,943 | 1 | | Saint Helena, Ascension and Tristan da Cunha | 2,166 | 0 | | Falkland Islands | 1,923 | 0 | | Montserrat | 1,403 | 8 | | Niue | 1,092 | 0 | | Tokelau | 80 | 0 | | Vatican City | 26 | 0 | | Pitcairn Islands | 4 | 0 | | Turkmenistan | 0 | 0 | | North Korea | 0 | 0 | |
|