Please master, simulate the web page capture web pages such as capture http://map.sogou.com/api/this web page, I write the program, if the network does not bring the following "/", will capture not, but site internet (http://tool.chinaz.com/Tools/PageCode.aspx), without the last "/" can be captured: http://map.sogou.com/api), what's his principle? My code is posted below. please make improvements
function file_get($url){ ob_start(); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, "./cookie.txt"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; CIBA)");curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_exec($ch); curl_close($ch); $content = ob_get_clean(); return $content;}
Reply to discussion (solution)
Add the following code:
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Because you capture http://map.sogou.com/api, the other response is 301rmb. Add this sentence to capture the html after the jump.
Add the following code:
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Because you capture http://map.sogou.com/api, the other response is 301rmb. Add this sentence to capture the html after the jump.
And cannot be obtained.
Add the following code:
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Because you capture http://map.sogou.com/api, the other response is 301rmb. Add this sentence to capture the html after the jump.
And cannot be obtained.
function file_get($url){ ob_start(); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, "./cookie.txt"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; CIBA)");curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,TRUE); curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_exec($ch); curl_close($ch); $content = ob_get_clean(); return $content;}
I have tested it, and it is OK.
CURLOPT_FOLLOWLOCATION