Heart failure (HF) is a life-threatening condition that poses a significant challenge on public health, particularly among the elder populations. To develop new diagnostic and therapeutic strategies for HF, we analyzed large-scale transcriptome sequencing data from HF patients as an exploratory approach. We identified 18 HF-related genes and developed a robust scoring model for HF diagnosis, by applying two machine learning algorithms for data analysis. Meanwhile, we evaluated and compared the predictive abilities of three bioinformatics methods in identifying potential HF treatment drugs. Significantly, an unconventional network-based proximity analysis, integrating multidimensional drug target information, outperformed other methods in the assessment of predictive ability. To validate these findings, we tested several candidate drugs in a mouse model transitioning from acute myocardial infarction (MI) to chronic HF. Among the candidates, mirtazapine exhibited cardioprotective effects in both early (1-week) post-MI and chronic HF (4-week post-MI) settings, while cabergoline showed potential efficacy primarily in the early post-MI phase. Additionally, the screened triamterene, used as a positive control, exhibited protective effects in both early post-MI and chronic HF stages. Mechanistic studies revealed that growth factor receptor-bound protein 14 and Ras-related protein Rab-3A were critical to the observed cardioprotection. These findings provide valuable evidence and insights for exploring potential therapeutic agents for HF treatment.