我们先来安装一下
pip install selenium
接着我们还要下载浏览器驱动 我用的是Firefox浏览器,所以下载Firefox驱动,当然你用别的浏览器也阔以,去相应的地方下载就行了 Chrome | https://sites.google.com/a/chromium.org/chromedriver/downloads ------------- | ------------- Edge: | https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Firefox: | https://github.com/mozilla/geckodriver/releases Safari: | https://webkit.org/blog/6900/webdriver-support-in-safari-10/
下载完之后,将geckodriver
放到/usr/local/bin
目录下(我是用fedora桌面)
#coding=utf-8
from selenium import webdriver
import time
driver = webdriver.Firefox() # oepn firefox
driver.get('https://developer.apple.com/account/') # ask url
time.sleep(17) #waiting for web loading
driver.switch_to.frame('aid-auth-widget') # change into iframe
driver.find_element_by_id('account_name_text_field').send_keys('511220@sohu.com') # insert appid
driver.find_element_by_id('sign-in').click() # click to continue
driver.find_element_by_id('remember-me').click() # click remember me
driver.find_element_by_id('password_text_field').send_keys('19942929') # insert password
time.sleep(3) # sleep for url change
driver.find_element_by_id('sign-in').click() # click to sign in