您好,登錄后才能下訂單哦!
selenium簡介
selenium 是一個web的自動化測試工具,不少學習功能自動化的同學開始首選selenium ,相因為它相比QTP有諸多有點:
selenium安裝(Windows)
方法1、通過pip 安裝
C:\Users\fnngj>python3 -m pip install selenium
方法2、通過下載包安裝
直接下載selenium包:
https://pypi.python.org/pypi/selenium
解壓,cmd進入目錄:
C:\selenium\selenium2.53.5> python3 setup.py install
python使用selenium模擬登陸淘寶
實例代碼
#coding=utf-8 import time import datetime import sys import os import random import logging from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver import ActionChains from selenium.webdriver.common.desired_capabilities import DesiredCapabilities def common_click(driver,element_id,sleeptime=3): actions = ActionChains(driver) actions.move_to_element(element_id) actions.click(element_id) actions.perform() time.sleep(sleeptime) def login_in(user,pwd): #open login page driver.get('https://login.taobao.com/member/login.jhtml') time.sleep(3) sb=driver.find_element_by_class_name("login-switch") commonclick(driver,sb) userbox=driver.find_element_by_id("TPL_username_1") pwdbox=driver.find_element_by_id("TPL_password_1") userbox.clear() userbox.send_keys(user) commonclick(driver,pwdbox) pwdbox.send_keys(pwd) loadmore=driver.find_element_by_id("J_SubmitStatic") commonclick(driver,loadmore) time.sleep(20) if __name__ == '__main__': DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.loadImages'] = True DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.userAgent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 " driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true']) driver.set_script_timeout(30) driver.set_page_load_timeout(30) login_in(user,password)
總結
以上就是本文關于python編程使用selenium模擬登陸淘寶實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。