├── README.md ├── ScrapePttAddress └── turkish-citizen /README.md: -------------------------------------------------------------------------------- 1 | # PTT Address Data Scraper 2 | 3 | A Laravel command to scrape address data (provinces, districts, neighborhoods) from PTT's postal code website. 4 | 5 | ## Features 6 | 7 | - Scrapes all provinces, districts, and neighborhoods from PTT 8 | - Saves data in JSON format 9 | - Shows progress with colored console output 10 | - Handles Turkish characters 11 | - Cross-platform compatible (Windows/Linux) 12 | - Rate limiting to prevent server overload 13 | - Error handling and recovery 14 | - Live progress tracking 15 | 16 | ## Requirements 17 | 18 | - PHP >= 7.4 19 | - Laravel >= 8.x 20 | - Composer 21 | - GuzzleHttp 22 | 23 | ## Installation 24 | 25 | 1. Install the required package: 26 | ```bash 27 | composer require guzzlehttp/guzzle 28 | ``` 29 | 30 | 2. Create the command: 31 | ```bash 32 | php artisan make:command ScrapePttAddress 33 | ``` 34 | 35 | 3. Copy the provided code to `app/Console/Commands/ScrapePttAddress.php` 36 | 37 | ## Usage 38 | 39 | Run the command: 40 | ```bash 41 | php artisan scrape:ptt-address 42 | ``` 43 | 44 | The script will: 45 | 1. Connect to PTT's website 46 | 2. Scrape all provinces 47 | 3. Get districts for each province 48 | 4. Get neighborhoods for each district 49 | 5. Save data to `storage/app/ptt_address_data.json` 50 | 51 | ## Output Format 52 | 53 | ```json 54 | [ 55 | { 56 | "il_id": "1", 57 | "il_adi": "ADANA", 58 | "ilceler": [ 59 | { 60 | "ilce_id": "12", 61 | "ilce_adi": "ALADAG", 62 | "mahalleler": [ 63 | { 64 | "mahalle_id": "1_2", 65 | "mahalle_adi": "AKOREN MAH", 66 | "posta_kodu": "01722" 67 | } 68 | ] 69 | } 70 | ] 71 | } 72 | ] 73 | ``` 74 | 75 | ## Error Handling 76 | 77 | - The script includes comprehensive error handling 78 | - Recovers from connection issues 79 | - Logs errors to console 80 | - Saves progress regularly 81 | 82 | --- 83 | 84 | # PTT Adres Veri Çekici 85 | 86 | PTT'nin posta kodu web sitesinden adres verilerini (il, ilçe, mahalle) çeken Laravel komutu. 87 | 88 | ## Özellikler 89 | 90 | - Tüm il, ilçe ve mahalleleri PTT'den çeker 91 | - Verileri JSON formatında kaydeder 92 | - Renkli konsol çıktısıyla ilerlemeyi gösterir 93 | - Türkçe karakterleri düzgün işler 94 | - Çoklu platform desteği (Windows/Linux) 95 | - Sunucu yükünü önlemek için hız sınırlaması 96 | - Hata yönetimi ve kurtarma 97 | - Canlı ilerleme takibi 98 | 99 | ## Gereksinimler 100 | 101 | - PHP >= 7.4 102 | - Laravel >= 8.x 103 | - Composer 104 | - GuzzleHttp 105 | 106 | ## Kurulum 107 | 108 | 1. Gerekli paketi yükleyin: 109 | ```bash 110 | composer require guzzlehttp/guzzle 111 | ``` 112 | 113 | 2. Komutu oluşturun: 114 | ```bash 115 | php artisan make:command ScrapePttAddress 116 | ``` 117 | 118 | 3. Verilen kodu `app/Console/Commands/ScrapePttAddress.php` dosyasına kopyalayın 119 | 120 | ## Kullanım 121 | 122 | Komutu çalıştırın: 123 | ```bash 124 | php artisan scrape:ptt-address 125 | ``` 126 | 127 | Script şunları yapacak: 128 | 1. PTT web sitesine bağlanır 129 | 2. Tüm illeri çeker 130 | 3. Her il için ilçeleri alır 131 | 4. Her ilçe için mahalleleri alır 132 | 5. Verileri `storage/app/ptt_address_data.json` dosyasına kaydeder 133 | 134 | ## Çıktı Formatı 135 | 136 | ```json 137 | [ 138 | { 139 | "il_id": "1", 140 | "il_adi": "ADANA", 141 | "ilceler": [ 142 | { 143 | "ilce_id": "12", 144 | "ilce_adi": "ALADAG", 145 | "mahalleler": [ 146 | { 147 | "mahalle_id": "1_2", 148 | "mahalle_adi": "AKOREN MAH", 149 | "posta_kodu": "01722" 150 | } 151 | ] 152 | } 153 | ] 154 | } 155 | ] 156 | ``` 157 | 158 | ## Hata Yönetimi 159 | 160 | - Script kapsamlı hata yönetimi içerir 161 | - Bağlantı sorunlarından kurtarır 162 | - Hataları konsola loglar 163 | - İlerlemeyi düzenli olarak kaydeder 164 | -------------------------------------------------------------------------------- /ScrapePttAddress: -------------------------------------------------------------------------------- 1 | cookieJar = new CookieJar(); 28 | $this->client = new Client([ 29 | 'cookies' => $this->cookieJar, 30 | 'headers' => [ 31 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0', 32 | 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 33 | 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' 34 | ] 35 | ]); 36 | } 37 | 38 | public function handle() 39 | { 40 | try { 41 | $this->output->title('PTT Adres Verisi Çekme İşlemi Başlatılıyor'); 42 | $addressData = []; 43 | 44 | $response = $this->client->get($this->baseUrl); 45 | $html = (string) $response->getBody(); 46 | 47 | if (!preg_match('/MainContent_DropDownList1".*?>(.*?)<\/select>/s', $html, $provinceSelect)) { 48 | throw new \Exception('İl listesi bulunamadı'); 49 | } 50 | 51 | preg_match_all('/