我的PHP项目出了问题。这部分代码不起作用 - 当我尝试连接到这个url时,它只给我404错误(echo $ pg;仅用于测试目的)。
$url='http://myanimelist.net/anime/110/Chuuka_Ichiban';
$ch = curl_init();
$found=0;
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 5.1; Edition Campaign 21) Presto/2.12.388 Version/12.14');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__file__) . '/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__file__) . '/cookies.txt');
curl_setopt($ch, CURLOPT_HTTPGET, true);
$pg = curl_get_page($ch);
while (strpos($pg, 'getSessionCookies') !== false)
{
$pg = curl_get_page($ch);
}
curl_close($ch);
echo $pg;
有趣的是,在这个上面几行的功能看起来几乎相同(呃,我复制并修改它)并且它正在工作。相同的代码,相同的网站。这是工作中的一个:
$baseurl=$url.$i;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 5.1; Edition Campaign 21) Presto/2.12.388 Version/12.14');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__file__) . '/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__file__) . '/cookies.txt');
$pg = curl_get_page($ch);
while (strpos($pg, 'getSessionCookies') !== false)
{
$pg = curl_get_page($ch);
}
curl_close($ch);
你可以帮我解决这个问题吗?我想尽快完成这个网站。感谢。