爬取网页时,返回的页面代码中包含JavaScript定时重定向问题
发布于 7 年前 作者 xugang2017 2995 次浏览 来自 问答

大哥大姐们帮帮忙,谢谢!

起因: 我在使用async模块进行异步并发访问一个PHP网站,url格式如下: http://…/zt_shop_order_list.php?xm=&page=1 http://…/zt_shop_order_list.php?xm=&page=2 … http://…/zt_shop_order_list.php?xm=&page=51

url需要设置cookie:

const cookie = ‘zt_user2=123456789; a=1; b=1; d=1; f=1; js=%E8%B4%A2%E5%8A%A1%E7%AE%A1%E7%90%86’

爬去代码如下: var fetchUrl = function (url, callback) { superagent .get(url) .set(‘Cookie’, cookie) .end(function (err, sres) { callback(null, sres.text); }) };

问题: 前面几十个url都可以正常爬取数据,但是到 http://…/zt_shop_order_list.php?xm=&page=51时,页面代码就变成了下面的样子: <html> <head> <meta http-equiv=“Content-Type” content=“text/html; charset=gb2312” /> <meta http-equiv=“pragma” content=“no-cache” /> <meta http-equiv=“cache-control” content=“no-store” /> <meta http-equiv=“Connection” content=“Close” /> <script> function JumpSelf(){
self.location="/…/zt_shop_order_list.php?xm=&page=52&WebShieldSessionVerify= ZKQ1syEzTq6dePTJPW6r";} </script> <script> setTimeout(“JumpSelf()”,700); </script> </head> <body></body> </html>

请问这是什么原因?

3 回复

估计是你爬的太快,对方反爬虫了把

@imhered 我最大数限制在3个,没敢爬的太快…

无标题.png

他的请求Cookie是这样的。

回到顶部