def get_generic_name(drug_name):
driver=None
try:
# Specify the path to the Chrome WebDriver
webdriver_path = "/home/ksamira/chromedriver_linux64/chromedriver" # Update this with the actual path
service = Service(webdriver_path)
# Set up Chrome options
options = webdriver.ChromeOptions()
options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
options.add_argument("start-maximized")
# Initialize the WebDriver with options
driver = webdriver.Chrome(service=service, options=options)
# Navigate to the DrugBank website
driver.get("https://go.drugbank.com/drugs")
# Find the search box by ID and type the drug name
search_box = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "query"))
)
search_box.send_keys(drug_name)
search_box.send_keys(Keys.ENTER)
# Wait for the element to be present
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".col-xl-4.col-md-9.col-sm-8.pr-xl-2"))
)
# Extract the text from the element
generic_name = element.text
except TimeoutException:
print(f"Timeout error for drug '{drug_name}': Element not found within the specified time")
generic_name = "Not Found"
except NoSuchElementException as e:
print(f"Element not found for drug '{drug_name}': {str(e)}")
generic_name = "Not Found"
except Exception as e:
print(f"Error for drug '{drug_name}': {str(e)}")
generic_name = "Not Found"
finally:
# Close the browser
driver.quit()
return generic_name
你好,我正在用python进行网络抓取。我在Moaxterm上工作。使用的服务器是:narval。我得到的错误消息是:消息:未知错误:找不到Chrome二进制文件
和AttributeError:“NoneType”对象没有属性“quit”
。我认为问题出在chrome二进制文件的位置上。我的电脑是Windows,里面有这个文件。我不知道如何在Moaxterm上提供它。我刚开始在Moaxterm上使用硒。如有任何帮助,我们将不胜感激。非常感谢。