JS -Pfad oder XPath -Syntax für dynamische Webseite: Extrahieren von TBODY -Informationen [geschlossen]HTML

HTML-Programmierer
Guest
 JS -Pfad oder XPath -Syntax für dynamische Webseite: Extrahieren von TBODY -Informationen [geschlossen]

Post by Guest »

Ich bin sehr neu in JS, XPath und HTML, aber ich versuche, einen Web -Schrubber für Data Mining -Zwecke zu erstellen. Pfade verweisen. Ich möchte grundsätzlich ein Skript, das die Tabellendaten liest, den Ligandennamen (erste Zeile), Ketten -ID -Info (zweite Zeile), Ligandformel (dritte Zeile) extrahiert und dann die .svg -Datei herunterladen, die in der 4. Zeile verknüpft ist ((in der 4. Zeile Welches wäre das Ligand 2D -Bild). Screenshot der Website + HTML -Struktur
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"

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post