失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php爬取html内容 php抓取网页html curl和file_get_contents通过get或post方式抓取网页内容 源代码

php爬取html内容 php抓取网页html curl和file_get_contents通过get或post方式抓取网页内容 源代码

时间:2018-11-20 02:34:28

相关推荐

php爬取html内容 php抓取网页html curl和file_get_contents通过get或post方式抓取网页内容 源代码

1、curl方式获取

<?php$a = '/123.html';$ch = curl_init($a);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');$f = curl_exec($ch);echo $f;

地址:/jianwicn/mixed/raw/master/taobao

2、file_get_contents获取

<?php$a = '/123.html';$opts = array('http'=>array('method'=>"GET",'header'=>"Accept-language: zh-cn\r\n" ."User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; 4399Box.560; .NET4.0C; .NET4.0E)" ."Accept: *//*"));$ctx = stream_context_create($opts);$x = file_get_contents($a,false,$ctx);echo $x;

如果无法获取,需要开启allow_url_fopen参数,参考/sh/article/details/105756477

下载地址:/jianwicn/mixed/raw/master/file_get_contents

更详细方法:/index.php/post/343.html

如果觉得《php爬取html内容 php抓取网页html curl和file_get_contents通过get或post方式抓取网页内容 源代码》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。