找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 5554|回复: 2

[求助] python爬虫模拟登录一个asp网站失败

1

主题

2

帖子

2

积分

贫民

积分
2
lsj754039701 发表于 2017-3-11 22:10:33 | 显示全部楼层 |阅读模式
1威望
本帖最后由 lsj754039701 于 2017-3-11 22:12 编辑

登录网址:http://218.6.128.130/web/web/mis/
  1. 主要代码:
  2. sess = requests.session()
  3. def login():
  4.     post_url = 'http://218.6.128.130/jiaoshi/bangong/main/check.asp'
  5.     # 密码账号就不写出来了
  6.     postdata = {
  7.     'user': '******',
  8.     'pwd': '',
  9.     'user1':'******',
  10.     'pwd1':'******',
  11.    
  12.     }
  13.     resp = sess.post(post_url, data=postdata, headers=headers, allow_redirects=True)
  14.     print resp.status_code
  15.     print 'url', resp.url
  16.     print "text", resp.text
  17.     print 'header', resp.headers
  18.     print("history", resp.history)
  19.     sess.cookies.save()
复制代码
  1. def getAim():
  2.     # 登录成功后想抓取的页面
  3.     url = "http://218.6.128.130/jiaoshi/bangong/main/index1"
  4.     resp = sess.get(url, headers=headers)
  5.     print resp.content.decode('gbk')
复制代码



执行login函数后的输出:
  1. 200
  2. url: http://218.6.128.130/jiaoshi/bangong/main/check.asp
  3. text:
  4. header: {'Content-Length': '0', 'X-Powered-By': 'ASP.NET', 'Set-Cookie': 'ASPSESSIONIDSQSCBSRB=CIEALMJAGNFCPNAPCCICMBHI; path=/', 'Server': 'Microsoft-IIS/7.5', 'Cache-Control': 'private', 'Date': 'Fri, 10 Mar 2017 07:05:38 GMT', 'Content-Type': 'text/html'}
  5. ('history', [])
  6. cookie: <RequestsCookieJar[<Cookie ASPSESSIONIDSQSCBSRB=CIEALMJAGNFCPNAPCCICMBHI for 218.6.128.130/>]>
复制代码



回复

使用道具 举报

0

主题

1

帖子

1

积分

贫民

积分
1
mickelfeng 发表于 2017-3-13 13:59:44 | 显示全部楼层
给个测试账号,我试试,
回复

使用道具 举报

2

主题

18

帖子

18

积分

贫民

积分
18
random7 发表于 2017-3-19 18:21:05 | 显示全部楼层
你这么写谁也不知道
用httpfox查看登陆过程的数据包 发送了什么 接收了什么 构造url和post的数据查看和httpfox中的有什么不一致。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表