Postingan

WEB SCRAPING

import requests from bs4 import BeautifulSoup # URL situs berita (ganti dengan situs lain jika diperlukan) url = "https://www.cnnindonesia.com/nasional" # Mengambil halaman web response = requests.get(url) # Cek apakah permintaan berhasil (kode status 200) if response.status_code == 200:     # Parsing halaman dengan BeautifulSoup     soup = BeautifulSoup(response.text, "html.parser")     # Mencari semua elemen berita (coba berbagai tag)     titles = soup.find_all(["h2"])  # Gunakan beberapa opsi     # Jika tidak ada hasil, beri peringatan     if not titles:         print("⚠ Tidak ditemukan berita! Coba periksa struktur HTML.")     # Menampilkan hasil di layar     else:         print("\n=== Daftar Berita ===\n")         for i, title in enumerate(titles[:10], 1):  # Ambil 10 berita pertama             print(f"{i...

WEB SCRAPPING

import requests   import pandas as pd   from bs4 import BeautifulSoup   #MENGAMBIL DATA DARI WEBSITE url = "https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population" response = requests.get(url) # Cek apakah permintaan berhasil if response.status_code == 200 :     print ( "Berhasil mengambil halaman!" ) else :     print ( f "Gagal! Kode status: {response.status_code} " ) #Parsing HTML dengan BeautifulSoup soup = BeautifulSoup(response.text, "html.parser" ) #Menemukan Tabel yang Dibutuhkan table = soup.find( "table" , { "class" : "wikitable" }) #Mengambil Data dari Tabel rows = table.find_all( "tr" ) #Menyimpan Data ke dalam Pandas DataFrame data = []   # List untuk menyimpan data for row in rows[ 4 :]:   # Lewati header tabel(mengambil data mulai baris ke-3 dari tabel)     cols = row.find_all([ "td" , "th" ])       if len (cols) >= 5 :           no = col...

Analisa Data

Gambar
Buatalah data di bawah ini dengan menggunakan MS Excel atau sejenisnya : buat sesuai dengan gambar ya...