PHP 利用 cUrl 抓取 HTTPS/HTTP 網頁
No Comments

發布:
更新:2016-04-25 20:16:50

最近不知道要發什麼,這篇這是純當筆記用。

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $data);
if (stripos($data,'https://')===0){
	//網址是https,設定SSL。
	curl_setopt($ch, CURLOPT_SSLVERSION,CURL_SSLVERSION_DEFAULT);
	curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
	curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
}
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36');
curl_setopt($ch, CURLOPT_MAXREDIRS, 999);
$html = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($html, 0, $header_size);
$html_body = substr($html, $header_size);
curl_close($ch);

 


This entry was posted in General, Functions, The Internet, Note, PHP By Weil Jimmer.

About Weil Jimmer

Hi! Everyone! My name is Weil Jimmer. This is my personal blog. I'm a webmaster of this site. I hope the site will be popular. Now, Let's go! Enjoy gaining more knowledge.
More Details About Me : https://weils.net/profile.php


Leave a message.

Only the first 10 comment will show.