Home  >  Article  >  Backend Development  >  再来一个爬虫,PHP cURL 带cookies模拟HTTP

再来一个爬虫,PHP cURL 带cookies模拟HTTP

WBOY
WBOYOriginal
2016-06-20 12:53:211177browse

抓取个json数据,不知道哪里错了。遂重写一个

curl

<?php header("content-type:text/html;charset=utf8");$curl = curl_init('https://www.phpcto.org/course/19/lesson/170');// 不输出header头信息curl_setopt($curl, CURLOPT_HEADER, 0);curl_setopt($curl, CURLOPT_COOKIE, ' PHPSESSID=q406pvav5da7st8q4ov6c482e0');// 伪装浏览器curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36');// 保存到字符串而不是输出curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$rs = curl_exec($curl);curl_close($curl);//echo $rs;$arr=json_decode($rs,true);print_r($arr);



snoopy

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn