使用curl抓取一个网页出现瓶颈

木木老蔫 2014-01-23 05:19:25
http://www.sgs.gov.cn/lz/etpsInfo.do?method=index
这个网站
输入上海科波勒之后查询后可以得到
点击查看详情后他发送了一个post到http://www.sgs.gov.cn/lz/etpsInfo.do?method=viewDetail
$etpsId = 290000032004051700672
用curl总是返回非法的访问方式,
我设置了refer,设置了setcookie都还是不成。哪位大神能解决吗
...全文
160 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2014-01-23
  • 打赏
  • 举报
回复
$url = 'http://www.sgs.gov.cn/lz/etpsInfo.do?method=index';

//$cookiejar = realpath('cookie.txt');
$url = 'http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch';
$ar = array('searchType' =>1, 'keyWords' => iconv('gbk', 'utf-8', '上海科波'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ar);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$t = curl_exec($ch);
curl_close($ch);

preg_match_all("/viewDetail\('(\d+)'\)/", $t, $r);
foreach($r[1] as $id) {
  echo "$id\n";
  $url = 'http://www.sgs.gov.cn/lz/etpsInfo.do?method=viewDetail';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  curl_setopt($ch, CURLOPT_REFERER, "http://www.sgs.gov.cn/lz/");
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "etpsId=$id");
//  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  $t = curl_exec($ch);
  curl_close($ch);
  echo $t;
}
木木老蔫 2014-01-23
  • 打赏
  • 举报
回复
引用 1 楼 PhpNewnew 的回复:
跳转打开 模拟浏览器参数加上 所有的参数都要提交清楚 如果目标页面有对提交的IP做判断,那就直接死心吧.
还没成功,难道真的限制了ip
木木老蔫 2014-01-23
  • 打赏
  • 举报
回复
引用 2 楼 xuzuning 的回复:
这个我已经写出来了,我是要的后面那个。。点击详细信息之后的
xuzuning 2014-01-23
  • 打赏
  • 举报
回复
黄袍披身 2014-01-23
  • 打赏
  • 举报
回复
跳转打开 模拟浏览器参数加上 所有的参数都要提交清楚 如果目标页面有对提交的IP做判断,那就直接死心吧.

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧