229 LAMPIRAN 230 231 Lampiran A Kode Python Scraping Kos Kode selengkapnya dapat diakses di : https://colab.research.google.com/drive/1Vg5X5z5N96ZdmewHBiFKXCrhnhPzcQ- A?usp=sharing import pandas as pd import requests from bs4 import BeautifulSoup from google.colab import drive import os from IPython.display import display from urllib.parse import quote_plus import time import random import re from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException, WebDriverException def mount_drive(): """ Mount Google Drive to access files Returns the path to Google Drive """ drive.mount('/content/drive') return '/content/drive/My Drive/' def load_csv_file(drive_path): """ Let user input the CSV file path and load it Returns the DataFrame and file path """ while True: try: file_path = input("Masukkan path file CSV dari Google Drive (contoh: Data/input.csv): ") full_path = os.path.join(drive_path, file_path) df = pd.read_csv(full_path) print("\nIsi file CSV:") display(df.head()) print(f"\nTotal baris data: {len(df)}") return df, full_path except Exception as e: print(f"Error: {str(e)}") print("Silakan coba lagi dengan path yang benar" ) def create_output_filename (original_path, start_row, end_row): """ Create output filename with row range information """ base_path = os.path.splitext(original_path)[ 0] return f"{base_path}_results_rows_{start_row}_to_{end_row}.csv" def get_row_range(total_rows): """ Let user select the range of rows to process Returns start_row and end_row indices """ while True: try: print("\nMasukkan range baris yang akan diproses:" ) print(f"Total baris tersedia: {total_rows} (indeks 0-{total_rows-1})") start = int(input("Baris awal (0 untuk dari awal): " )) end = int(input(f"Baris akhir ({total_rows-1} untuk sampai akhir): " )) if 0