相关文章推荐
自信的登山鞋  ·  std::begin (Iterator) ...·  1 年前    · 
忐忑的镜子  ·  mysql ...·  2 年前    · 
温暖的机器人  ·  javascript循环的区别 ...·  2 年前    · 
from selenium.webdriver import Chrome from selenium import webdriver download_location = ' C:\\Users\\Administrator\\Downloads ' chrome_options = webdriver.ChromeOptions() prefs = { ' download.default_directory ' : download_location, ' download.prompt_for_download ' : False, ' download.directory_upgrade ' : True, ' safebrowsing.enabled ' : False, ' safebrowsing.disable_download_protection ' : True} chrome_options.add_experimental_option( ' prefs ' , prefs) chrome_options.add_argument( " --headless " ) driver = Chrome(chrome_options= chrome_options) driver.command_executor._commands[ " send_command " ] = ( " POST " , ' /session/$sessionId/chromium/send_command ' ) params = { ' cmd ' : ' Page.setDownloadBehavior ' , ' params ' : { ' behavior ' : ' allow ' , ' downloadPath ' : download_location}} command_result = driver.execute( " send_command " , params) print ( " response from browser: " ) for key in command_result: print ( " result: " + key + " : " + str(command_result[key])) # 这里是随便选了一个可以下载的连接,无心骚扰。 driver.get( " http://www.yundama.com/apidoc/YDM_SDK.html " ) clone_box = driver.find_element_by_xpath( ' /html/body/div[4]/div[2]/div/p[11]/a ' ) clone_box.click() time.sleep( 10 ) driver.quit()

需要注意的有两点:

1、你的chrome浏览器要60以上。

2、注意下载路径,wins下必须是 \  而不是 /

我相信努力的人运气不会差,未来会给我一双梦想的翅膀