如何输入搜索文本并通过Selenium和Python从搜索结果中检索值

2024-03-29 08:21:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从以下网站提取数据: https://www.polymergenome.org/explore/index.php?m=1

请在搜索框中输入“CCOCCO”,然后单击“预测属性”。从预测表中,我想提取‘玻璃化转变温度(K)’。你知道吗

在我的应用程序中,我有一个带有1000s字符串的pandas数据帧,类似于ro'CCOCCO'。我想定义一个函数,它接受pandas数据帧字符串,把它放在上面网站的搜索框中,并提取“玻璃化转变温度(K)”。你知道吗

在我无法从beautifulsoup得到我想要的东西之后,互联网搜索告诉我硒就是答案。我开始在这个应用程序中使用它,但没有成功。我真的很感激任何帮助和指导。你知道吗


Tags: 数据字符串httpsorg应用程序pandasindex网站
1条回答
网友
1楼 · 发布于 2024-03-29 08:21:50

在搜索框中输入CCOCCO并单击预测属性后,从预测表中提取玻璃化转变温度(K)的值,即可使用以下解决方案:

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    options = Options()
    options.add_argument("start-maximized")
    options.add_argument("disable-infobars")
    options.add_argument(" disable-extensions")
    driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\ChromeDriver\chromedriver_win32\chromedriver.exe')    
    driver.get('https://www.polymergenome.org/explore/index.php?m=1')       
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='large_input_no_round ui-autocomplete-input' and @id='keyword_original']"))).send_keys("CCOCCO")
    driver.find_element_by_xpath("//input[@class='dark_blue_button_no_round' and @value='Predict Properties']").click()
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table[@class='record']//tbody/tr[@class='record']//following::td[7]/center/font/font"))).get_attribute("innerHTML"))
    
  • 控制台输出:

    206 ±       29
    

相关问题 更多 >