The efficient photoelectrocatalytic decomposition of water by polymers needs to satisfy high carrier separation efficiency and low complexation rate. Polyaniline (PANI) possesses a large conjugated structure due to the presence of a large number of aromatic ring structures, but the lack of polar functional groups in it leads to a high complexation rate. In the present study, a simple chemical bath polymerization method was used to prepare crosslinked polyaniline reticulation (PANI-Tx, X is the melamine/polyaniline concentration ratio) with cyanamide molecules. The photoelectric properties of PANI-T0.1, PANI-T0.5 and pure PANI structures were characterized by detailed photoelectrochemical tests. From the results, it was observed that the catalytic activity of PANI formed by polymerization of different concentrations of cyanuric ammonia molecules varies, and the catalytic performance decreases as the degree of cross-linking increases. In particular, in the linear voltammetric test, the current density of PANI-T0.1 reached 1.39 mA/cm2 at 1.23 V vs. RHE, which is 2.78 and 6.95 times higher than that of PANI-T0.5 and PANI, respectively. In addition to this, the electronic structures and electron transfer numbers of PANI-T and PANI were also calculated by density functional theory (DFT). Among them, the molecular dipole moment in the PANI-T structure is significantly stronger than that in the PANI structure, which further explains the stronger performance of PANI-T than PANI. This study will provide new ideas for the application of PANI photocatalysts in new energy fields.