Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial PHP curl 抓包问题

PHP curl 抓包问题

Jun 23, 2016 pm 01:45 PM

用curl抓取网页书据,成绩,课表都是用这种方法抓取的,但是抓取就不行了,报500错误

这是用httpwatch抓包工具抓取的页面,cookie正确拿到

这是要抓取的界面,数据通过post传输

<html>	<head>		<meta charset=gbk>	</head>	<body>		<form action="" method="post">		学号:<input type="text" name="user">		<br>		密码:<input type="password" name="password">		<br>		<input type="submit" name="login" value="登录">		</form>	</body><?php	if(isset($_POST["login"])) {	$login = $_POST["user"];	$password = $_POST["password"];	$url = "http://202.117.64.25/loginAction.do";	$fields = "dllx=dldl&zjh=201224080126&mm=201224080126";	$cookie1 = "D:\wamp\www\cookielogin.txt";	$cookie2 = "D:\wamp\www\cookie.txt";	$ch = curl_init();	curl_setopt($ch, CURLOPT_URL, $url);	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");	curl_setopt($ch, CURLOPT_POST, 1);	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie1);	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);	$result = curl_exec($ch);	curl_close($ch);	$url = "http://202.117.64.25/xszxcxAction.do?oper=tjcx";	$fields = "zxxnxq=2014-2015-1-1&zxXaq=0&zxJxl=0011&zxZc=1&zxJc=1%2C2&zxxq=1&pageSize=20&page=1&currentPage=1&pageNo=1";	$ch = curl_init();	curl_setopt($ch, CURLOPT_URL, $url);	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");	curl_setopt($ch, CURLOPT_POST, 1);	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie1);	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);	$result = curl_exec($ch);	echo $result;}?></html>
Copy after login

PHP代码

报错界面


回复讨论(解决方案)

第一:带上CURLOPT_REFERER试试,对方是不是有可能判断了页面来源
第二:对方的登陆页是否有隐藏参数,如果有的话需要先访问登陆页获取隐藏值再提交
第三:没看见你什么地方提交了登录的账号和密码,就是自己这边POST过来的账号和密码

$url = "http://202.117.64.25/loginAction.do";
$fields = "dllx=dldl&zjh=201224080126&mm=201224080126";
这是提交账户和密码!
CURLOPT_REFERER 要加什么?

找到两个隐藏参数,但是貌似没什么用

第一:带上CURLOPT_REFERER试试,对方是不是有可能判断了页面来源
第二:对方的登陆页是否有隐藏参数,如果有的话需要先访问登陆页获取隐藏值再提交
第三:没看见你什么地方提交了登录的账号和密码,就是自己这边POST过来的账号和密码


$url = "http://202.117.64.25/loginAction.do";
$fields = "dllx=dldl&zjh=201224080126&mm=201224080126";
这是提交账户和密码!
CURLOPT_REFERER 要加什么?

找到两个隐藏参数,但是貌似没什么用

帮你测试了一下,登录是没问题的,已经登录成功,主要问题出在你第二次请求的参数上,检查一下参数,抓取你第二个页面上所有的参数下来,另外JAVA的这个报错不是很懂!

帮你测试了一下,登录是没问题的,已经登录成功,主要问题出在你第二次请求的参数上,检查一下参数,抓取你第二个页面上所有的参数下来,另外JAVA的这个报错不是很懂!


你抓取成功了吗?

大家帮忙看看,怎么回事???

你的流程和代码都有问题!正确的流程应该是:
1、访问 http://202.117.64.25/
获取 cookie。因为他的 sessionid 在这个页面发出的
2、访问 http://202.117.64.25/loginAction.do 并发送 post 表单数据
3、第2步返回的是一个框架页,你得根据需要进入某个框架
比如访问 http://202.117.64.25/menu/s_top.jsp 可以得到已登录信息:欢迎光临 黄小龙
测试代码

<xmp><?phpinclude 'curl/curl_get.php';$url = 'http://202.117.64.25/';curl_get($url);$url = "http://202.117.64.25/loginAction.do";$d = 'dllx=dldl&zjh=201224080126&mm=201224080126';curl_get($url, $d);echo curl_get('http://202.117.64.25/menu/s_top.jsp');echo curl_get('http://202.117.64.25/menu/mainFrame.jsp');echo curl_get('http://202.117.64.25/xsxxviewAction.do');
Copy after login
Copy after login

curl_get.php
<?phpfunction curl_get($durl, $data=array()) {  $cookiejar = realpath('cookie.txt');  $t = parse_url($durl);  $ch = curl_init();  curl_setopt($ch, CURLOPT_URL,$durl);  curl_setopt($ch, CURLOPT_TIMEOUT,5);  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);  curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);  curl_setopt($ch, CURLOPT_ENCODING, 1); //gzip 解码  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  if($data) {    curl_setopt($ch, CURLOPT_POST, 1);    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  }  $r = curl_exec($ch);  curl_close($ch);  return $r;}
Copy after login
Copy after login

你的流程和代码都有问题!正确的流程应该是:
1、访问 http://202.117.64.25/
获取 cookie。因为他的 sessionid 在这个页面发出的
2、访问 http://202.117.64.25/loginAction.do 并发送 post 表单数据
3、第2步返回的是一个框架页,你得根据需要进入某个框架
比如访问 http://202.117.64.25/menu/s_top.jsp 可以得到已登录信息:欢迎光临 黄小龙
测试代码

<xmp><?phpinclude 'curl/curl_get.php';$url = 'http://202.117.64.25/';curl_get($url);$url = "http://202.117.64.25/loginAction.do";$d = 'dllx=dldl&zjh=201224080126&mm=201224080126';curl_get($url, $d);echo curl_get('http://202.117.64.25/menu/s_top.jsp');echo curl_get('http://202.117.64.25/menu/mainFrame.jsp');echo curl_get('http://202.117.64.25/xsxxviewAction.do');
Copy after login
Copy after login

curl_get.php
<?phpfunction curl_get($durl, $data=array()) {  $cookiejar = realpath('cookie.txt');  $t = parse_url($durl);  $ch = curl_init();  curl_setopt($ch, CURLOPT_URL,$durl);  curl_setopt($ch, CURLOPT_TIMEOUT,5);  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);  curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);  curl_setopt($ch, CURLOPT_ENCODING, 1); //gzip 解码  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  if($data) {    curl_setopt($ch, CURLOPT_POST, 1);    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  }  $r = curl_exec($ch);  curl_close($ch);  return $r;}
Copy after login
Copy after login


非常感谢你,成功了,但是还是不知道为什么?
这是我最终代码
<?phpinclude './curl/curl_get.php';$url = "http://202.117.64.25/loginAction.do";$d = 'dllx=dldl&zjh=201224080126&mm=201224080126';curl_get($url, $d);echo curl_get('http://202.117.64.25/xszxcxAction.do?oper=tjcx', 'zxxnxq=2014-2015-1-1&zxXaq=0&zxJxl=0011&zxZc=11&zxJc=2&zxxq=2&pageSize=20&page=1&currentPage=1&pageNo=');?>
Copy after login

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles