#Coding:utf-8 fromSeleniumImportWebdriverdefMain (): Driver=Webdriver. Firefox ()#Change page display text #Web page source code: # #<body> #<div id= "result" ></div> #<script>document.getelementbyid ("result"). InnerText = ' Hello world ';</script> #</body> # #driver.get (' http://example.webscraping.com/places/default/dynamic ') #What = Raw_input (' What: ') # Driver.execute_script ("document.getElementById (' result '). InnerText = '%s '"%what) #input (":")Driver.get ('Http://example.webscraping.com/places/default/search') driver.find_element_by_id ('Search_term'). Send_keys ('.') #Change the drop-down second option to Driver.execute_script ("document.getElementById (' page_size '). Options[1].text = '" ) driver.find_element_by_id ('Search'). Click () driver.implicitly_wait (30) Links= Driver.find_elements_by_css_selector ('#results a') Countries= [Link.text forLinkinchLinks]#driver.close () PrintcountriesPrintLen (countries)if __name__=='__main__': Main ()
Selenium manually executing JavaScript statements