python注册用户名和密码登录_python实现自动登录需要用户名和密码的网站
如果想用瀏覽器自動(dòng)打開的話,可以嘗試一下樓上兄臺(tái)的建議:
Selenium是基于webdriver的著名自動(dòng)化測(cè)試工具,可以輕松搞定樓主的問題。
比如我下面這段給出的example,可以完成你的需求,模擬登錄人人
# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
wd = webdriver.Firefox()
wd.get("http://www.renren.com")
wd.maximize_window()
try:
"""這段可以查看selenium的源碼,屬于smart wait"""
email = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'email')),message=u'元素加載超時(shí)!')
email.send_keys("*** 你的賬號(hào) ***")
passwd = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'password')),message=u'元素加載超時(shí)!')
passwd.send_keys("*** 你的密碼 ***")
wd.find_element_by_id("login").click() #點(diǎn)擊登錄
except NoSuchElementException as e:
print e.message
感謝閱讀。
總結(jié)
以上是生活随笔為你收集整理的python注册用户名和密码登录_python实现自动登录需要用户名和密码的网站的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 批量生成数组_JavaScript【重温
- 下一篇: websocket python爬虫_p