python selenium环境配置Firefox和Chrome

1、下载Selenium库,可以使用pip install selenium 
https://pypi.python.org/pypi/selenium/ 
2、下载驱动 
Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads 
Firefox: https://github.com/mozilla/geckodriver/releases 
3、配置环境变量 
需要将chrome和firefox的.exe路径和驱动路径均加入path中 
这里写图片描述 
比如我电脑中chrome.exe的路径为: 
C:\Program Files (x86)\Google\Chrome\Application 
chrome的驱动路径为: 
E:\Program Files (x86)\chromedriver_win32 
4、需要重启电脑,就okay了。

测试成功:

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://baidu.com')
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.keys import Keys

browser= webdriver.PhantomJS()
browser.get("https://baike.baidu.com/")
browser.find_element_by_tag_name("input").send_keys("Python")
browser.find_element_by_tag_name("button").click()
soup = BeautifulSoup(browser.page_source, "html.parser")
print (soup.prettify())
browser.quit()
posted @ 2017-08-17 23:16  失落的黎明  阅读(490)  评论(0编辑  收藏  举报