Selenium入门记录_001_环境配置和Hello World!

来源:互联网 发布:软件开发的发展趋势 编辑:程序博客网 时间:2024/06/06 02:07

站在巨人的肩膀上,参考虫师写的selenium+Python的pdf教程
https://www.cnblogs.com/fnng/category/349036.html

软件 版本 系统 Win7 64位 Chrome 59.0 selenium 3.0.2 Python 35 chromedriver 2.3.1(根据Chrome版本找到对应的版本驱动)

具体的的步骤,跟着大神的pdf走。这边在试行第一个Hello World程序时遇到问题。头疼医头脚疼医脚找了半天,还是没解决。

#百度到下面这些设置,实践发现都没用# chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"# os.environ["webdriver.chrome.driver"] = chromedriver# options = webdriver.ChromeOptions()# options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])# options.add_argument("--user-data-dir=C:/Users/wangyimiao/AppData/Local/Google/Chrome/User Data/Default")# driver = webdriver.Chrome(chrome_options=options)

最后把chromedriver放到python配置过path的根目录下就完美解决了。(其实pdf也有写,还是要看的仔细)

然后运行selenium的hello world!程序

#coding=utf-8from selenium import webdriver import timedriver = webdriver.Chrome() #使用chrome的driverdriver.get("http://www.baidu.com")driver.find_element_by_id("kw").send_keys("Selenium2")driver.find_element_by_id("su").click()time.sleep(5)driver.quit()

执行后的结果就如下图所示,自动打开百度,并进行了一次搜索:
执行结果

原创粉丝点击