Home>

I want to search for a certain protein from a site called PDB and download it all at once.
In def btn_click ():
search_check = browser.find_element_by_name ("entry PDB")
search_check.click ()
I can't press the checkbox well at. please tell me.
I would like to select a checkbox called PDB of the data file format of the following site.

https://www.rcsb.org/downloads?ids=3W8R,3ASY,3ASZ,3W34

code
import tkinter
from selenium import webdriver
from time import sleep
import requests
from bs4 import BeautifulSoup
root = tkinter.Tk ()
root.title (u "protein search")
root.geometry ("500x500")
Static1 = tkinter.Label (text = u'protein')
Static1.pack ()
EditBox = tkinter.Entry (width = 50)
EditBox.insert (tkinter.END, "")
EditBox.place (x = 170, y = 100)
EditBox.pack ()


def btn_click ():
    EditBox_value = EditBox.get ()
    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)
    sleep (1)
    # ------------------------------------------------- ---
    search_id1 = browser.find_element_by_id ("menu1")
    search_id1.click ()
    sleep (1)
    search1 = browser.find_element_by_xpath ("/ html/body/div [2]/div/div/div [3]/div [2]/div [2]/table/tr/td [2]/div/div [1] ]/div [2]/div [1] ")
    search1.click ()
# ------------------------------------------------- -
    sleep (2)
    search_check = browser.find_element_by_name ("entry PDB")
    search_check.click ()
    search_final = browser.find_element_by_xpath ("/ html/body/div [2]/div/div/div [2]/div/div [1]/form/div [3]/div [1]/button")
    search_final.click ()
    search_final2 = browser.find_element_by_xpath ("/ html/body/div [2]/div/div/div [2]/div/div [2]/div/div/div [2]/table/tr [2]/td/div [1]/a/h4/font [1]/font ")
    search_final2.click ()
    browser.back ()
    browser.close ()
btn = tkinter.Button (root, text ='Search for proteins', command = btn_click)
btn.place (x = 170, y = 200)
root.mainloop ()
Error message
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-2-a563075303f8>", line 37, in btn_click
    search_check = browser.find_element_by_name ("entry PDB")
  File "C: \ ANACONDA \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py", line 496, in find_element_by_name
    return self.find_element (by = By.NAME, value = name)
  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": "[name =" entry PDB "]"}
  (Session info: chrome = 86.0.4240.198)
  • Answer # 1

    import tkinter
    from selenium import webdriver
    from time import sleep
    import requests
    from bs4 import BeautifulSoup
    root = tkinter.Tk ()
    root.title (u "protein search")
    root.geometry ("500x500")
    Static1 = tkinter.Label (text = u'protein')
    Static1.pack ()
    EditBox = tkinter.Entry (width = 50)
    EditBox.insert (tkinter.END, "")
    EditBox.place (x = 170, y = 100)
    EditBox.pack ()
    def btn_click ():
        EditBox_value = EditBox.get ()
        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)
        sleep (2)
        # ------------------------------------------------- ---
        search_id1 = browser.find_element_by_id ("menu1")
        search_id1.click ()
        sleep (5)
        # ------------------------------------------------- -
        search_check = browser.find_element_by_xpath ("// div [text () ='Download Selected Files']")
        search_check.click ()
        sleep (3)
        browser.switch_to.window (browser.window_handles [1])
        search_final = browser.find_element_by_id ("coordinatesOptions")
        search_final.click ()
        # search_final2 = browser.find_element_by_xpath ("// button [text () ='Generate File Batches for Download']")
        # search_final2.click ()
        sleep (8)
        browser.close ()
        browser.switch_to.window (browser.window_handles [0])
        browser.close ()
    btn = tkinter.Button (root, text ='Search for proteins', command = btn_click)
    btn.place (x = 170, y = 200)
    root.mainloop ()