douguazhi5966 2017-06-03 00:34
浏览 27

使用php刮刮asp.net生成的网页。 在localhost中成功,在服务器中失败

I am trying to scrape a web page generated by ASP.NET using PHP language.

In localhost I got the info that I need (the book data), but when I try in server. I got the following error: Object Moved Here It can be checked here

Reading about the problem, I realize that scraping pages generated by ASP.net is difficult because you have to recover a VIEWSTATE and another kind of info. I try to get it, but I'm not sure if it is the cause of the problem or it can be another reason.

My code is:

$url = "http://www.panamericana.com.co/busqueda/el%20laberinto%20de%20los%20espiritus/0";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$result = curl_exec($ch);
preg_match_all("/id=\"__VIEWSTATE\" value=\"(.*?)\"/", $result, $arr_viewstate);
$viewstate = urlencode($arr_viewstate[1][0]);
$options = array(
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_HEADER => true,
    CURLOPT_FOLLOWLOCATION => false, 
    CURLOPT_ENCODING => "", 
    CURLOPT_USERAGENT => "spider", 
    CURLOPT_AUTOREFERER => true, 
    CURLOPT_CONNECTTIMEOUT => 120, 
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => '__VIEWSTATE=' . $viewstate);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本