A previous post described Getting Ligand ID for multiple PDB files, using the PDBe API (https://www.ebi.ac.uk/pdbe/pdbe-services). The result is a csv file containing the ligand PDB id, that can be used to download the molecular structures from the PDB as shown below in this Jupyter Notebook.