php模拟爬虫获取其它站点网页内容

php如何模拟爬虫获取其它站点网页内容?

demo代码如下:

<?php
 header('Access-Control-Allow-Origin:*'); 
 header('Access-Control-Allow-Methods:POST,GET,OPTIONS'); 
 header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With,X-PINGOTHER,Content-Type'); 
 header('Access-Control-Allow-Headers:Authorization,lpy');
 
$url = $_GET['url'];

$opts = array(
   	'http'=>array(
		'method'=>"GET",
		"timeout"=>20,
		'header'=>"User-Agent: Spider \r\n",
   	)
);
$context = stream_context_create($opts);
$html = file_get_contents($url,0,$context,0,150000);

echo $html;
?>


本文为@艺文笔记原创文章,转载请注明出处:https://www.xuwenyan.com/archives/2135,非常感谢!
已是最前文章 下一篇: