Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import requests from bs4 import BeautifulSoup def fetch_data_rows(url): response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') table = soup.find('table', {'class': 'wikitable'}) if table: rows = table.find_all('tr') data_rows = [] for row in rows: cells = row.find_all('td') data = [cell.get_text(strip=True) for cell in cells] if data: data_rows.append(data) return data_rows else: print("Table 'wikitable' was not found.") else: print("Failed to retrieve the page. Status code:", response.status_code) return [] url = 'https://en.wikipedia.org/wiki/List_of_European_Union_member_states_by_population' data_rows = fetch_data_rows(url) countries_dictionary = {} for row in data_rows: country = row[0] population = row[1] percent = row[2] percent = percent.strip('%') percent = float(percent) if percent else None population = ''.join(filter(str.isdigit, population)) if population: population = int(population) countries_dictionary[country] = { 'population': population, 'percent': percent, } print(countries_dictionary)
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)