pythonでtkinter,seleniumを使って、入力させたタンパク質名を検索させるプログラムを作りたいのですが、まずEditBoxで入力させてその結果を得てsearch_id.send_keys(EditBox_value)で開いたブラウザで検索させたいのですが出来ません。何が駄目でしょうか。
import tkinter
from selenium import webdriver
from time import sleep
import requests
from bs4 import BeautifulSoup
root=tkinter.Tk()
root.title(u"タンパク質検索")
root.geometry("500x500")
#ラベル
Static1 = tkinter.Label(text=u'タンパク質')
Static1.pack()
EditBox = tkinter.Entry(width=50)
EditBox.insert(tkinter.END,"")
EditBox.place(x=170,y=100)
EditBox.pack()
EditBox_value = EditBox.get()
btn = tkinter.Button(root, text='タンパク質を検索する', command=btn_click)
btn.place(x=170, y=200)
#実行ボタン
def btn_click():
browser = webdriver.Chrome('chromedriver.exe')
browser.get("https://www.rcsb.org/")
search_id = browser.find_element_by_id("search-bar-input-text")
search_id.send_keys(EditBox_value)
#エラーメッセージ
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ANACONDA\lib\tkinter_init_.py", line 1705, in call
return self.func(*args)
File "<ipython-input-22-42d55a33050c>", line 32, in btn_click
search_id1 = browser.find_element_by_id("menu1")
File "C:\ANACONDA\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\ANACONDA\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\ANACONDA\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\ANACONDA\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="menu1"]"}
(Session info: chrome=86.0.4240.198)
回答1件
あなたの回答
tips
プレビュー