Maison >développement back-end >tutoriel php >再来一个爬虫,PHP cURL 带cookies模拟HTTP
抓取个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