search
HomeBackend DevelopmentPHP Tutorial急:用snoopy抓取EMS验证码,远程模拟查询单号,无法获取JSessionID的问题?

会员life169之前在PHP版块发过一篇文章叫( 用snoopy抓取EMS验证码,远程模拟查询单号,取得查询结果)
链接是:http://topic.csdn.net/u/20100715/23/d58f2006-40ea-4cab-82e3-3bbcf4cd1e9f.html


可是我在测试的过程中却遇到一个问题,JsessionID,经常会取不到,

session_start(); 
include("Snoopy.class.php"); 
$url = "http://www.ems.com.cn/qcgzOutQueryNewAction.do?reqCode=gotoSearch"; 
$url2 = "http://www.ems.com.cn/qcgzOutQueryNewAction.do"; 

$snoopy = new Snoopy;
$snoopy->fetch($url); //获取所有内容 
print_r($snoopy->headers);

打印头信息,返回的是:
Array ( [0] => HTTP/1.1 200 OK [1] => Content-Type: text/html; charset=GB2312 [2] => X-Powered-By: Servlet/2.4 JSP/2.0 [3] => Accept-Ranges: bytes [4] => Connection: close [5] => Date: Tue, 15 Mar 2011 11:24:53 GMT [6] => Age: 1876 [7] => Content-Length: 22804 ) 

正确的返回信息应当是:
Array ( [0] => HTTP/1.1 200 OK [1] => Cache-Control: no-cache="set-cookie" [2] => Connection: close [3] => Date: Fri, 11 Mar 2011 07:42:04 GMT [4] => Content-Type: text/html; charset=GB2312 [5] => Set-Cookie: JSESSIONID=N5SMs1dMW1Wy8LJ48Z1ZhP1p2kS1GSgY5twTNxcYpz1MvgYZk0LQ!195316506; path=/ [6] => X-Powered-By: Servlet/2.4 JSP/2.0 ) 

前面返回的里面没有JSESSIONID, 导致在后面的查询中返回不了查询结果, 我已经整了2天了,在网上查了大量资料,还是没有头绪,现在有一个奇怪现象,如果在浏览器打开ems.php页面,过一段时间再刷新页面后,又会返回正确的headers信息,但是过一阵又不能正确返回,为什么会出现这种情况, 希望有大虾能帮我看看是怎么回事? 急


回复讨论(解决方案)

百度了一下ems的查询,有不少连接是抱怨无法查询的。
所以我怀疑ems,并没有把银子花在公众查询服务器上,在高负载下,服务器有些吃力。

应该是服务器的问题。

这个问题没法解决吗,具体发生的原因是什么? 因为有的时间段又是可以的,如果我不通过Snoopy,而是直接通过火狐浏览器访问EMS的网址,通过工具查看COOKIE,实际上里面还是会产生一个JESSIONID,为什么通过Snoopy 就获取不到这个JessionID呢?

life169。麻烦再帮我解答一下这个疑问?

昨天我也在firefox里测试了一会,还好,连续刷新都抓到了sesssionid
你说的这个现象,我以前也碰到,至今无解。

用curl吧,比snoopy稳定得多,也强大得多。在csdn里有我的源码

你好,能不能告诉你写的关于curl具体的文章链接?我没找到

另外,使用CURL 也能实现Snoopy 实现的这个EMS查询功能吗?好像贴里你有说用CURL测试成功,能否提供一下你的源码给到我参考一下。

我的邮箱是:59325460@qq.com

已经发到你的邮箱里了

life169, 非常感谢,收到你的源码,不过在使用CURL测试过程中,仍然不能返回正确数据,总是提示“页面停留时间过长导致邮件查询标志丢失,请刷新查询页面。”   

搞不明白是怎么回事,还请继续指点迷津。

恩 以前做的代码不能用了
ems的查询地址变了,
也多了两个提交所需要的数据

reqCode browseBASE
myEmsbarCode 7967913886707
mailNum EE082209212CS
E4E5AFF694E4FAD581D8FC8 vpc9
optijiaot.x 15
optijiaot.y 13

这个是以前没有的 像是由js生成的,原文件里看不见。

那现在要怎么改,才能通过CURL的方式正确的获取到内容,Snoopy如果可以获取到JSESSIONID,就可以正确获取到数据。

你给我的源码需要改哪些地方吗

查询地址我之前就已经改过了,然后我觉着既然之前通过Snoopy有时可以正确查询, 可以得知CURL不成功 可

能与新增加的两个提交所需要的数据没有太大的关系,可能是其它方面的需要设置,测试的时候,

testcookie.txt 并不能生成,只会生成一个testcookiebb.txt 文件,以前从来没玩过CURL,希望

life169能帮我解决这个问题。。。

恩 现在有点忙 晚上 我弄个完整版的代码给你

好的,非常感谢life169,在这个问题上我已经整了快三天时间了!有点抓狂了。

life169,完整版的代码搞好了吗?

恩 好了 到这里下吧

http://download.csdn.net/source/3100240

太感谢了,我先测试。

测试完结,太完美了,可以正确稳定的采集EMS的数据。感谢life169,帮我了一个大忙。

life169 你好,我下载的程序,结果报错,能给我发一个新的吗pangz@sohu.com 谢谢

sea1126  你好,能把你运行成功的代码发给我吗,我运行的结果是报错,谢谢,
pang@sohu.com

恩 好了 到这里下吧

http://download.csdn.net/source/3100240

life169,您好,你这个代码我测试成功了,但是更进一步,可以绕过输入验证码这个环节么?你这个程序还是需要输入验证码的!

谢谢哥哥

能发个给我吗? 我太需要这个了。 fob001@qq.com

能给我发一份吗?我也需要这个,谢谢!

yuxianhua@vip.qq.com

我也需要 bilwy@vip.qq.com 谁有发我一份

5分啊,穷人下不起啊,发份给我好么?1991753135@qq.com,谢谢

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
What data can be stored in a PHP session?What data can be stored in a PHP session?May 02, 2025 am 12:17 AM

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

How do you start a PHP session?How do you start a PHP session?May 02, 2025 am 12:16 AM

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

What is session regeneration, and how does it improve security?What is session regeneration, and how does it improve security?May 02, 2025 am 12:15 AM

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

What are some performance considerations when using PHP sessions?What are some performance considerations when using PHP sessions?May 02, 2025 am 12:11 AM

PHP sessions have a significant impact on application performance. Optimization methods include: 1. Use a database to store session data to improve response speed; 2. Reduce the use of session data and only store necessary information; 3. Use a non-blocking session processor to improve concurrency capabilities; 4. Adjust the session expiration time to balance user experience and server burden; 5. Use persistent sessions to reduce the number of data read and write times.

How do PHP sessions differ from cookies?How do PHP sessions differ from cookies?May 02, 2025 am 12:03 AM

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

How does PHP identify a user's session?How does PHP identify a user's session?May 01, 2025 am 12:23 AM

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

What are some best practices for securing PHP sessions?What are some best practices for securing PHP sessions?May 01, 2025 am 12:22 AM

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

Where are PHP session files stored by default?Where are PHP session files stored by default?May 01, 2025 am 12:15 AM

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

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

Video Face Swap

Video Face Swap

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

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use