使用 模拟登陆 抓取学校系统的晨跑数据,失败了,请问大神

WBOY
Release: 2016-06-13 11:57:15
Original
964 people have browsed it

使用 模拟登陆 抓取学校系统的晨跑数据,失败了,请教大神
最近在学习php的模拟登陆,就想拿学校的体育教学系统实践一下,但失败了。请教大神,我的代码到底错在了哪?

【一些信息】
登录系统的地址:http://210.35.75.247:8080/student/studentFrame.jsp
(用户名:1101001,密码:1101001,角色:学生)
查晨跑的地址:http://210.35.75.247:8080/student/queryCheckInfo.jsp

【代码如下】

<?php  <br />$cookie_file = tempnam('./temp','cookie');<br />$login_url = 'http://210.35.75.247:8080/student/studentFrame.jsp';<br />$post_fields  = 'userName=1101001&passwd=1101001';<br /><br />$ch = curl_init($login_url);<br />curl_setopt($ch, CURLOPT_HEADER, 0);<br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />curl_setopt($ch, CURLOPT_POST, 1);<br />curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);<br />curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);<br />curl_exec($ch);<br />curl_close($ch);<br /><br />$url = 'http://210.35.75.247:8080/student/queryCheckInfo.jsp';<br />$ch = curl_init($url);<br />curl_setopt($ch, CURLOPT_HEADER, 0);<br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);<br />curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);<br />curl_exec($ch);<br />curl_close($ch);<br />?>
Copy after login


【第一次发帖,拜谢!】
------解决方案--------------------
别客气我也只是菜鸟,一起研究学习下
首先声明几个名词...
框架页 student/studentFrame.jsp 表单提交的action地址
学生信息页 student/studentInfo.jsp 是框架页的iframe自动加载的src
晨跑成绩 student/queryCheckInfo.jsp
用firebug跟踪了一下登陆流程,发现框架页的iframe加载的学生信息后面带了参数?username=...&passwd=....,猜测真正的登陆流程应该在学生信息页。我把登陆失败的页面不echo保存在文件中看了下,框架页的html和登陆成功几乎相同,只是多了一段跳转js。利用学生信息页的JSESSIONID登陆成功了,和框架页的对比下,不一样。蛋疼的管理系统

<br /><?php<br /><br />$url1 = 'http://210.35.75.247:8080/student/studentInfo.jsp';<br />$url2 = 'http://210.35.75.247:8080/student/queryCheckInfo.jsp';<br />$name = '1101001';<br />$pw = '1101001';<br />$params = array(<br />    'userName' => $name,<br />    'passwd' => $pw,<br />);<br /><br />$ch = curl_init();<br />curl_setopt($ch, CURLOPT_URL, $url1 . '?' . http_build_query($params));<br />curl_setopt($ch, CURLOPT_HEADER, 1);<br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />$con = curl_exec($ch);<br /><br />preg_match('/Set-Cookie: (.*);/Us', $con, $match);<br />$cookie = $match[1];<br /><br />curl_setopt($ch, CURLOPT_URL, $url2);<br />curl_setopt($ch, CURLOPT_HEADER, 0);<br />curl_setopt($ch, CURLOPT_COOKIE, $cookie);<br />$con = curl_exec($ch);<br />curl_close($ch);<br /><br />echo $con;<br /><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template