簡體   English   中英

WebScrape - 通過 - Selenium/Python 查找元素

[英]WebScrape - Find Element by - Selenium/Python

我的代碼進入一個網站,點擊一個下拉菜單並只抓取下拉菜單的第一個條目

但我想要下拉列表中的所有條目(如果你運行我的代碼,你可以看到這一點)

理想情況下,我會通過 find_element 使用 class 名稱來做到這一點,但對我來說只有 xpath 有效,也許我做錯了什么。

任何幫助抓取所有條目將不勝感激

import time
from selenium import webdriver
driver = webdriver.Chrome()
bracket=[]
driver.get('https://www.eventscribe.net/2021/ASPENePosters/searchbyposterbucket.asp?f=PosterTrack&pfp=BrowsebyPosterBucket')
time.sleep(1)
driver.get('https://www.eventscribe.net/2021/ASPENePosters/searchbyposterbucket.asp?f=PosterTrack&pfp=BrowsebyPosterBucket')
time.sleep(2)


firstDropdown=driver.find_element_by_xpath('//*[@id="bucketPres"]/li[1]/div')
firstDropdown.click()
time.sleep(1)
li=driver.find_elements_by_xpath('//*[@id="bucketPres"]/div[1]/li[1]/a/div') #trying to get all entries
for item in li:
    print(item.text)

只需將 /li[1] 更改為 //li 即可獲取所有 lis。

li=driver.find_elements_by_xpath('//*[@id="bucketPres"]/div[1]//li/a/div')

你也可以這樣做。

values=[item.text for item in driver.find_elements_by_xpath('//*[@id="bucketPres"]/div[1]//li/a/div')] #trying to get all entries
print(values)

輸出

P86 - Enteral Feeding Volumes: Can You Trust Your Numbers? A Pilot Study Optimizing Accuracy of Documentation in the Hospital Setting
P87 - Cost-effectiveness Comparison of High Protein Enteral Feedings Used in the ICU: Retrospective Adjusted Analysis
P88 - Predictability of nitrogen balance for critically ill patients with severe traumatic injuries
P89 - Vitamin D Deficiency Among Adult Lung and Liver Transplant Patients: A Retrospective Review
P90 - Calorie Deficit Calculator to Facilitate Adequate Nutrition in the Trauma ICU
P91 - The effect of oxandrolone on weight loss and muscle mass in acute spinal cord injury patients
P92 - Application of preoperative fasting abbreviation protocol in patients subject to femur fracture surgery
P93 - Reduction of hypercalcemia following readjustment of target serum 25-hydroxy vitamin D concentration during cholecalciferol therapy in vitamin D deficient, critically ill patients
P94 - Gastric Feeding Intolerance in Critically Ill Patients During Sustained Pharmacologic Neuromuscular Blockade
P95 - Beneficial effects of a long-acting GLP-2 analog, HM15912, after switching from daily or weekly GLP-2 analog drugs in animal models
P96 - Utilization of Indirect Calorimetry for Calculation of Nutritional Goals and its Effect in Ventilator-free days and Muscle Thickness in Septic Mechanically Ventilated Patients
P97 - Pilot Quality Improvement Study: Exploring PEG Placements in Critically Ill COVID-19 Patients
P99 - Adequacy and complications of enteral nutritional therapy in critically ill patients with COVID-19
P100 - Challenges in Parenteral Nutrition in Adult Ultra-Short Gut: A Case of Cachexia
P101 - Retrospective Examination of Copper Supplementation in Burn Patients
P102 - Utilization of Peptide Based Diets in Severely Ill Patients
P103 - Association of Nutritional Delivery on Skeletal Muscle Wasting and Inflammation in Critically Ill Adult Patients: A Systematic Review
P98 - Impact of Vasoactive Medication on Enteral Nutrition in Pediatric Acute Respiratory Distress Syndrome
P104 - The Effect of Preoperative Non NPO Feeding Protocol on Nutrition Delivery and Pneumonia Incidence in Critically-Ill Trauma Patients
P105 - The impact of a carbohydrate loading drink on postprandial glycemic responses and gastric emptying in adults with prediabetes and type 2 diabetes mellitus
P106 - Increasing Hypermetabolism during Hospitalization in COVID-19 Patients Undetected by Common Predictive Energy Equations
P107 - Respiratory Quotient as a Predictor of Clinical Outcomes in Intubated, Critically Ill COVID-19 Patients
P108 - Micronutrient INTake from Enteral nutrition in critically ill adult patients expressed as a percentage of the Australia and New Zealand Nutrient Reference Values: a retrospective observational study.
P109 - The effect of intermittent or continuous feeding and amino acid concentration on urea-to-creatinine ratio in critical illness
P110 - NUTRIC Scores in Trauma Patients: A Comparison of Energy and Protein Needs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM