2016-11-05 34 views
0

我想讓Python,Chrome和ActionChains保存一個網頁。Python,硒,Chrome和ActionChains來保存網頁

該代碼似乎在任何情況下都可以在計算機上正常工作,但不是另一種。

我檢查了代碼,也嘗試了在selenium action chains no effect給出的建議,但它仍然不起作用。

哪裏出錯了?謝謝。

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.support.ui import Select 
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.action_chains import ActionChains 
from selenium.webdriver.common.keys import Keys 
import win32com.client as comclt 

chromedriver = "c:\Python27\\chromedriver.exe" 
os.environ["webdriver.chrome.driver"] = chromedriver 

driver = webdriver.Chrome(chromedriver) 
driver.maximize_window() 

aaa = driver.get("https://sg.yahoo.com/?p=us") 
time.sleep(3) 

save_me = ActionChains(driver).key_down(Keys.CONTROL).key_down('s').key_up(Keys.CONTROL).key_up('s') 
save_me.perform() 
time.sleep(2) 
wsh= comclt.Dispatch("WScript.Shell") 
wsh.AppActivate("chrome") 
time.sleep(1) 
wsh.SendKeys("{ENTER}") 

driver.quit() 

回答

0

它看起來像Chrome和Chromedriver(32位,64位)的版本很重要。試過另一個版本,它可能會正常工作。