PHP curl returning blank page -
can show me how compose request using curl php? need scrape website, code use (given below) returns blank page. want send
accept-encoding, useragent, , cookie
request:
mozilla/5.0 (x11; linux i686) applewebkit/535.1 (khtml, gecko) chrome/13.0.782.99 safari/535.1 accept-encoding: gzip
to
thanks!
the code tried use (returned blank page):
<? $url='https://example.com'; $ch = curl_init($url); curl_setopt($ch, curlopt_httpheader, $request_headers); $request_headers = array(); $request_headers[] = 'accept-encoding: gzip'; $request_headers[] = 'client: apple'; curl_setopt($ch, curlopt_cookie, 'insertedmycookiehere'); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (x11; linux i686) applewebkit/535.1 (khtml, gecko) chrome/13.0.782.99 safari/535.1'); curl_setopt($ch, curlopt_returntransfer, true); $curl_scraped_page = curl_exec($ch); curl_close($ch); echo $curl_scraped_page; ?>
did wrong?
this worked me :
$url='http://example.com'; /* incorrectly used https website */ $ch = curl_init($url); $request_headers = array(); $request_headers[] = 'accept-encoding: gzip'; $request_headers[] = 'client: apple'; curl_setopt($ch, curlopt_httpheader, $request_headers); /* moved line here */ curl_setopt($ch, curlopt_cookie, 'insertedmycookiehere'); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (x11; linux i686) applewebkit/535.1 (khtml, gecko) chrome/13.0.782.99 safari/535.1'); curl_setopt($ch, curlopt_returntransfer, true); $curl_scraped_page = curl_exec($ch); curl_close($ch); echo $curl_scraped_page;
Comments
Post a Comment