- 论坛徽章:
- 0
|
本帖最后由 bxfqing 于 2014-09-08 21:33 编辑
2014-07-30-PM:
花费了2周时间,第一个python终于完成了,虽然还有很多不理解的地方,但是在这个过程中,还是学习了一些web开发的基础知识
INFO >>> Reply successfully!
Current reply/当前次数[8],Loop replies number/本次循环次数[10],Totaldone/总计已完成[22],Limit/回帖总数限制[100]
开始睡眠,[10]s
INFO >>> lasted reply: , user id:
INFO >>> Sleep [80]sec for skip reply continual limit,睡眠[80]秒,等待连续回复限制
Current reply/当前次数[9],Loop replies number/本次循环次数[10],Totaldone/总计已完成[22],Limit/回帖总数限制[100]
开始睡眠,[80]s
2014-07-28-PM:
功能终于调试通了,开始代码重构
<?xml version="1.0" encoding="utf-8"?>
<root><![CDATA[<script type="text/javascript" reload="1">if(typeof succeedhandle_fastpost=='function') {succeedhandle_fastpost('forum.php?mod=redirect&tid=8164648&goto=lastpost#lastpost', '非常感谢,回复发布成功,现在将转入主题页,系统最多需要1分钟才能同步完成,如果不能显示,请稍候……[ 点击这里转入主题列表 ]', {'fid':'29','tid':'8164648','pid':'124095702','from':'','sechash':''});}</script>]]></root>
更换了流程,以前的写法,导致cookie始终无法在bbs域生效:
- Method 2:
- 1. GET http://passport.feng.com/?r=user/login&sso[name]=%E5%A8%81%E9%94%8B%E8%AE%BA%E5%9D%9B&sso[apps]=2&sso[verify]=bc1ce0c20dad09f5855266d8a0530010
- 2. POST http://passport.feng.com/?r=user/loginProcess
- 3. GET http://bbs.feng.com/api/uc.php?time=1406430109&code=
- 4. GET http://passport.feng.com/?r=user/profile
- 5. GET http://bbs.feng.com/read-htm-tid-8157115.html
复制代码 ==================
当前进度: 2014-07-24-PM:
登陆流程:
1. http://passport.feng.com/?r=user/login
2. jump to http://passport.feng.com/?r=user/loginProcess
3. jump to http://passport.feng.com/api/uc.php?time=xxx&code=xxxx
4. jump to http://passport.feng.com/?r=user/profile
5. jump to random post to show content ,e.g. http://bbs.feng.com/read-htm-tid-8157115.html
可以从profile读取,但是切换到tid页面,还是提示未登陆-
- <h1>个人资料</h1>
- <table width="700" border="0" cellpadding="0" cellspacing="0" class="line-table fr" style="margin-right:40px; -margin-right:20px">
- <tr>
- <td width="70">帐户ID</td>
- <td> <span style="margin-left:20px">(注册日期:2014-07-22)</span></td>
- </tr>
- <tr>
- <td>UID:</td>
- <td>8655459</td>
- </tr>
- <tr>
- <td>E-Mail:</td>
- <td>
复制代码- <div class="pt hm">
- 您需要登录后才可以回帖 <a href="member.php?mod=logging&action=login" onclick="showWindow('login', this.href)" class="xi2">登录</a> | <a href="member.php?mod=register" class="xi2">注册</a>
- </div>
复制代码 =============原帖=============
我在练习如何使用python登陆Discuz!论坛,以bbs.feng.com作为试验对象
通过网上的教程,了解一些使用python模拟登陆网站的sample
使用firefox+httpfox抓包,然后分析post,header
现在example已经写出来了,但是登陆,保存cookie后,打开页面还是提示我没有登陆
期望是能从 最后一句 print result.read的打印中, 能过滤出登陆信息,而实际上是提示未登陆
<div class="pt hm">
您需要登录后才可以回帖 <a href="member.php?mod=logging&action=login" onclick="showWindow('login', this.href)" class="xi2">登录</a> | <a href="member.php?mod=register" class="xi2">注册</a>
</div>
请问下面的代码,哪里写的有问题啊? 这个代码复制后就可以在本地运行的
登陆流程分析:
1. http://passport.feng.com/?r=user/login
2. jump to http://passport.feng.com/?r=user/loginProcess
3. jump to http://passport.feng.com/api/uc.php?time=xxx&code=xxxx
4. jump to http://passport.feng.com/?r=user/profile
- # -*- coding: utf-8 -*-
- # !/usr/bin/python
- import urllib2
- import urllib
- import cookielib
- import re
- import pdb
- auth_url = 'http://passport.feng.com/?r=user/loginProcess'
- test_url = 'http://bbs.feng.com/read-htm-tid-8150265.html';
- # 登陆用户名和密码
- data = {
- "Kaf_Model_Form_Login[login]":"",
- "Kaf_Model_Form_Login[password]":"",
- 'Kaf_Model_Form_Login[rememberMe]':'0'
- }
- # urllib进行编码
- post_data=urllib.urlencode(data)
- # 发送头信息
- headers = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
- 'Accept-Language':'en-US,en;q=0.5',
- 'Host': 'bbs.feng.com',
- 'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0'
- }
- # 初始化一个CookieJar来处理Cookie
- cookieJar=cookielib.CookieJar()
- # 实例化一个全局opener
- opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
- # 获取cookie
- req=urllib2.Request(auth_url,post_data,headers)
- result = opener.open(req)
- #pdb.set_trace()
- # 访问测试页面 自动带着cookie信息
- result = opener.open(test_url)
- # 显示结果
- print result.read()
复制代码 |
|