import selenium.webdriver as webdriver
print("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()
href=""
links=browser.get_element_by_class("//slp f//a")
print(links)
browser.close()
search_key=input("Enter the movie name : ")
get_results("what is the imdb rating of "+search_key)
如何从网页打印特定的行到终端?
我可以使用find_element_by_xcode()
或get_element_by_class()
吗?
答案 0 :(得分:0)
您可以使用CSS Selector
,xPath
等。例如,您有此搜索results并且您想要打印评分:
然后你可以找到这样的元素:
links = browser.find_elements_by_xpath("//div[@class = 'slp f']/text()") # find all elements with given selector
for link in links
print(link) # prints in the terminal current link value
# for example ' Rating: 8,4/10 - 432,408 votes'
有关如何使用Python
var b = new Array();
for (var n = 0; n < 10; n++)
{
b[n] = document.getElementById("b" + n);
}
查找元素的详细信息。