如何输入搜索文本并通过Selenium和Python从搜索结果中检索值
我正在尝试从以下网站提取数据: 请在搜索框中输入“CCOCCO”,然后单击“预测属性”。从预测表中,我想提取“玻璃化转变温度(K)” 在我的应用程序中,我有一个带有1000s字符串的熊猫数据帧,类似于ro'CCOCCO'。我想定义一个函数,它接受pandas数据帧字符串,把它放在上面网站的搜索框中,并提取“玻璃化转变温度(K)”如何输入搜索文本并通过Selenium和Python从搜索结果中检索值,python,selenium,selenium-webdriver,web-scraping,webdriver,Python,Selenium,Selenium Webdriver,Web Scraping,Webdriver,我正在尝试从以下网站提取数据: 请在搜索框中输入“CCOCCO”,然后单击“预测属性”。从预测表中,我想提取“玻璃化转变温度(K)” 在我的应用程序中,我有一个带有1000s字符串的熊猫数据帧,类似于ro'CCOCCO'。我想定义一个函数,它接受pandas数据帧字符串,把它放在上面网站的搜索框中,并提取“玻璃化转变温度(K)” 在我无法从beautifulsoup获得我想要的东西后,互联网搜索告诉我selenium就是答案。我开始在这个应用程序中使用它,但没有成功。非常感谢您的帮助和指导。一
在我无法从beautifulsoup获得我想要的东西后,互联网搜索告诉我selenium就是答案。我开始在这个应用程序中使用它,但没有成功。非常感谢您的帮助和指导。一旦您在搜索框中输入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