Wenn es eine effiziente Möglichkeit gibt, dies mit einer Standardmethode zu tun, wäre dies sehr geschätzt. Ich habe mit der Absicht gemacht, die Ligandeninformationen zu extrahieren: < /p>
Code: Select all
# --- Extract Ligand Information ---
# We use the nth-child approach to match the JS paths you provided
time.sleep(2) # Ensure dynamic content is loaded
ligand_info_list = []
try:
# Grab the second in the #LigandsMainTable
second_tbody = driver.find_element(By.CSS_SELECTOR, "#LigandsMainTable > tbody:nth-child(2)")
# Find all rows in that tbody whose ID starts with "ligand_row_"
ligand_rows = second_tbody.find_elements(By.CSS_SELECTOR, "tr[id^='ligand_row_']")
for row in ligand_rows:
# 1) Ligand ID (e.g. ATP)
try:
lig_name_el = row.find_element(By.CSS_SELECTOR, "td:nth-child(1) > a:nth-child(1)")
lig_name = lig_name_el.text.strip()
except:
lig_name = ""
# 2) PDB chain in
try:
lig_chain_el = row.find_element(By.CSS_SELECTOR, "td:nth-child(2) > div")
lig_chain = lig_chain_el.text.strip()
except:
lig_chain = ""
# 3) Ligand formula
try:
lig_formula_el = row.find_element(By.CSS_SELECTOR, "td:nth-child(3)")
lig_formula = lig_formula_el.text.strip()
except:
lig_formula = ""
# Combine first three columns into a single text
combined_ligand_text = f"{lig_name} (chain: {lig_chain}, formula: {lig_formula})"
if not ligand_info_list:
ligand_info_list = "EMPTY"
except Exception as e:
ligand_info_list = "EMPTY"