Heim  >  Artikel  >  Backend-Entwicklung  >  再来一个爬虫,PHP cURL 带cookies模拟HTTP

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

WBOY
WBOYOriginal
2016-06-20 12:53:211143Durchsuche

抓取个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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn