Liver cancer is a malignant tumor that develops on or inside the liver. Hedyotis diffusa Willd (HDW) plays a significant role in anti-tumor activities; however, its mechanism against liver cancer remains unclear. This study aims to evaluate the immunotherapeutic mechanism of HDW in treating liver cancer through network pharmacology, bioinformatics analysis, and experimental validation. Network pharmacology was utilized to identify the active components and potential targets of HDW from the TCMSP database. A potential target protein-protein interaction (PPI) network was constructed using the STRING database, followed by function and pathway enrichment analysis of the targets using GO and KEGG methods. In addition, the key targets for HDW against liver cancer were identified using five different algorithms in Cytoscape. The TCGA and HPA databases were used to assess the mRNA and protein expression of core target genes in normal liver and liver cancer tissues and their relationship with overall survival in liver cancer, as well as their role in immune infiltration. Molecular docking between the core components of HDW and the core targets was performed using PyMOL software. The effects of HDW on the proliferation and apoptosis of liver cancer cells were examined using MTT and flow cytometry. The regulatory effects of the core component quercetin on core targets were validated using RT-qPCR and Western blot. A total of 163 potential targets were identified by searching for intersections among 7 types of active components and all potential and liver cancer targets. PPI network analysis revealed the core targets IL6 and TNF. GO enrichment analysis involved 2089 biological processes, 76 cellular components, and 196 molecular functions. KEGG enrichment analysis suggested that the anti-cancer effects of HDW might be mediated by the AGE-RAGE signaling pathway, IL-17 signaling pathway, TNF signaling pathway, PI3K-Akt signaling pathway, and NF-κB signaling pathway. Database validation of key targets showed that mRNA and protein expression results for the IL6 gene were contradictory, while those for the TNF gene were consistent, both being underexpressed in liver cancer. Importantly, the expression of IL6 and TNF was related to the infiltration of 24 types of immune cells, with the highest correlation with macrophages. Molecular docking showed that IL6 and TNF had high binding stability with quercetin, with binding energies of - 7.4 and - 6.0kJ∙mol-1, respectively. Experimental validation showed that quercetin inhibited liver cancer cell proliferation and promoted apoptosis in a dose-dependent manner, with protein results indicating that quercetin downregulated the mRNA and protein expression of IL6 and TNF, and upregulated key proteins in the AGE-RAGE signaling pathway, AGEs, and RAGE. This study comprehensively elucidates the activity, potential targets, and molecular mechanisms of HDW against liver cancer, providing a promising strategy for the scientific basis and treatment mechanism of traditional Chinese medicine in treating liver cancer.