I am using Google search for finding the element, as it seems easier to navigate than IMDB.
import selenium.webdriver as webdriverprint("This program finds the imdb rating of a movie or TV series!!!")def get_results(search_term): url="https://www.google.com" browser=webdriver.Safari() browser.get(url) search_box= browser.find_element_by_id("lst-ib") search_box.send_keys(search_term) search_box.submit() links = browser.find_element_by_id("//div[@class = 'slp f']/text()")#this line is problematic, should i use xpath?how? print(links)search_key=input("Enter the movie name : ")get_results("what is the imdb rating of "+search_key)
and here is the error...
This program finds the imdb rating of a movie or TV series!!!Enter the movie name : inceptionTraceback (most recent call last): File "web1.py", line 15, in <module> get_results("what is the imdb rating of "+search_key) File "web1.py", line 10, in get_results links = browser.find_element_by_id("//div[@class = 'slp f']/text()") File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 353, in find_element_by_id return self.find_element(by=By.ID, value=id_) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 957, in find_element'value': value})['value'] File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute self.error_handler.check_response(response) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace)selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
Please be specific. Thank you!