Option 1: Bus
Outside of Taipei Main station exit Z3, you will see a big tent that sells tickets to Keelung. The bus number that leaves Taipei Main station is number 1813.
Option 2: Train Railway Administration (TRA) website here
If you have the Easycard, you don’t have to get any additional tickets. Just go to TRA platform number 4, scan in your Easycard. This will cost about 35 Taiwan New Dollar. There is a train to Keelung every 15 minutes.
Both option will take about 45 minutes.