search

用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>

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');

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;}

你的流程和代码都有问题!正确的流程应该是:
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');

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;}


非常感谢你,成功了,但是还是不知道为什么?
这是我最终代码
<?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=');?>
Statement
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
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

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

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Framework Security Features: Protecting against vulnerabilities.Framework Security Features: Protecting against vulnerabilities.Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)