啟動Chrom瀏覽器
下載chromedriver:
http://chromedriver.storage.googleapis.com/index.html
當時找chromedriver與chrome的的對應版本的好麻煩,如今整理下:
驅動的下載地址如下:
http://chromedriver.storage.googleapis.com/index.html
我下載的是2.29,對應的Chrome瀏覽器下載的下圖中綠色標記的那個,下載完后將exe文件放在“C:\Users\Administrator\AppData\Local\Google\Chrome\Application”路徑下,即Chrome快捷方式的路徑下
然后將上面的路徑添加到path中
下載瀏覽器:https://www.chromedownloads.net/chrome32win-stable/
以上設置完畢后PyCharm運行時還是報莫名其妙的錯誤,這時重啟PyCharm,OK了
以下是模擬登錄京東商城簽到的,可惜點登錄時要輸入圖形驗證碼,卡在這里、、、
1 import time 2 3 from selenium import webdriver 4 import os 5 6 username = "jiangpr_ok@163.com" # 請替換成你的用戶名 7 password = "d123456789d" # 請替換成你的密碼 8 9 driver = webdriver.Chrome() # 選擇Chrome瀏覽器 10 # driver = webdriver.Firefox() 11 driver.get(url='http://vip.jd.com') # 打開京東會員網站 12 time.sleep(1) 13 14 15 driver.find_element_by_link_text('賬戶登錄').click() 16 driver.find_element_by_id('loginname').click() 17 driver.find_element_by_id('loginname').send_keys(username) 18 driver.find_element_by_id('nloginpwd').click() 19 driver.find_element_by_id('nloginpwd').send_keys(password) 20 21 driver.find_element_by_id('loginsubmit').click() 22 time.sleep(1) 23 driver.find_element_by_id('signIn').click() 24 driver.close()