PHP curl 抓包问题
用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¤tPage=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¤tPage=1&pageNo=');?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

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

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
