首页 > 代码库 > selenium手动执行JavaScript语句
selenium手动执行JavaScript语句
#coding:utf-8 from selenium import webdriver def main(): driver = webdriver.Firefox() # 改变网页显示文字 # 网页源代码: # <html> # <body> # <div id="result"></div> # <script>document.getElementById("result").innerText = ‘Hello World‘;</script> # </body> # </html> # 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(‘.‘) # 将下拉第二个选项改为1000 driver.execute_script("document.getElementById(‘page_size‘).options[1].text = ‘1000‘") driver.find_element_by_id(‘search‘).click() driver.implicitly_wait(30) links = driver.find_elements_by_css_selector(‘#results a‘) countries = [link.text for link in links] # driver.close() print countries print len(countries) if __name__ == ‘__main__‘: main()
selenium手动执行JavaScript语句
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。