Maison > Article > développement back-end > 使用 模拟登陆 抓取学校系统的晨跑数据,失败了,请问大神
使用 模拟登陆 抓取学校系统的晨跑数据,失败了,请教大神
最近在学习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 />?>
<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 />