2016-11-05 112 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位)的版本很重要。试过另一个版本,它可能会正常工作。