2017年7月25日 星期二

[Python] 用python開啟firefox

方法1: 1) Download and unzip Geckodriver. 2) Mention the path while initiating the driver: driver = webdriver.Firefox(executable_path='/your/path/to/geckodriver')

 方法2: Download geckodriver from here . Download the right version for the computer you are using Unzip the file you just downloaded and cut/copy the ".exe" file it contains Navigate to C:{your python root folder}. Mine was C:\Python27. Paste the geckodriver.exe file in this folder. Restart your development environment. Try running the code again, it should work now.

 我用了方法2(把geckodriver.exe放在firefox資料夾裡),程式碼如下:
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver=webdriver.Firefox() driver.get("http://www.hinet.net")