Python登陆人人网
#!coding:utf-8 import urllib2 import urllib import cookielib def renrenBrower(url,user,password): #登陆页面,可以通过抓包工具分析获得,如fiddler,wireshark login_page = "http://www.renren.com/PLogin.do" try: #获得一个cookieJar实例 cj = cookielib.CookieJar() #cookieJar作为参数,获得一个opener的实例 opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) #伪装成一个正常的浏览器,避免有些web服务器拒绝访问。 opener.addheaders = [('User-agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')] #生成Post数据,含有登陆用户名密码。 data = urllib.urlencode({"email":user,"password":password}) #以post的方法访问登陆页面,访问之后cookieJar会自定保存cookie opener.open(login_page,data) #以带cookie的方式访问页面 op=opener.open(url) #读取页面源码 data= op.read() return data except Exception,e: #print str(e) pass #访问某用户的个人主页,其实这已经实现了人人网的签到功能。 print renrenBrower("http://www.renren.com/home","17326057580","******")
Python登陆qq邮箱
#!coding:utf-8 import sys from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.PhantomJS(service_args=['--ssl-protocol=any']) def test(): try: driver.get('http://www.baidu.com') #访问百度首页 driver.save_screenshot('1.png') driver.get('http://www.sina.com.cn') #访问新浪首页 driver.save_screenshot('2.png') driver.back() #回退到百度首页 driver.save_screenshot('3.png') driver.forward() #前进到新浪首页 driver.save_screenshot('4.png') except Exception as e: print(e) driver.quit() #模拟登陆qq空间 #driver.get('http://ui.ptlogin2.qq.com/cgi-bin/login?pt_no_onekey=1&style=9&appid=1006102&s_url=http%3A%2F%2Fxiaoqu.qq.com%2Fmobile%2Fbarindex.html%3F_lv%3D29313%26_bid%3D128%26_wv%3D1027%26from%3Dshare_link%23bid%3D37469%26type%3D%26source%3Dindex%26scene%3Drecent%26from%3Ddongtai%26webview%3D1&low_login=0&hln_css=http%3A%2F%2Fpub.idqqimg.com%2Fqqun%2Fxiaoqu%2Fmobile%2Fimg%2Fnopack%2Flogin-logo.png') url = "https://mail.qq.com/cgi-bin/loginpage?autologin=n&errtype=1&clientuin=1191146282¶m=&sp=&tfcont=22%20serialization%3A%3Aarchive%205%200%200%204%200%200%200%208%20authtype%201%204%209%20clientuin%2010%201191146282%206%20domain%206%20qq.com%202%20vm%203%20wsk&r=a6b2e30d656c2e3549edf8b414c331d5" url = "https://mail.qq.com/" url = "https://mail.qq.com/cgi-bin/loginpage?autologin=n&errtype=1&clientuin=764309404¶m=&sp=&tfcont=22%20serialization%3A%3Aarchive%205%200%200%204%200%200%200%208%20authtype%201%204%209%20clientuin%2010%201191146282%206%20domain%206%20qq.com%202%20vm%203%20wsk&r=a6b2e30d656c2e3549edf8b414c331d5" driver.viewportSize={'width':1024,'height':800} #重要这句! driver.maximize_window() #driver.get('https://i.qq.com/?s_url=http%3A%2F%2Fuser.qzone.qq.com%2F1191146282') driver.get(url) #elementi= driver.find_element_by_class_name('login_frame') driver.switch_to_frame('login_frame') driver.delete_all_cookies() #找到账号密码登录按钮 #butt = driver.find_element_by_id("#switcher_plogin") #butt.click() #driver.save_screenshot('1.png') #butt = driver.find_element_by_id("login_button") #butt.click() #name = driver.find_element_by_name("TPL_username") name = driver.find_element_by_name("u") #输入账号 name.send_keys('1191146282') password = driver.find_element_by_id('p') #输入密码 password.send_keys('*****') password.send_keys(Keys.RETURN) driver.save_screenshot('2.png') #butt = driver.find_element_by_id("login_button") #点击登陆 driver.find_element_by_id('login_button').click() #刷新 driver.refresh() print('页面标题:', driver.title) # 页面标题 print(driver.current_url) # 当前页面url #保存截图 driver.refresh() driver.save_screenshot('3.png') #print driver.page_source