Warning: file_get_contents: failed to open stream: Redirection limit reached, aborting

前端 未结 4 1543
北海茫月
北海茫月 2020-12-03 22:40

I read over 20 related questions on this site, searched in Google but no use. I\'m new to PHP and am using PHP Simple HTML DOM Parser to fetch a URL. While this script works

4条回答
  •  时光说笑
    2020-12-03 23:21

    Using cURL you would need to have the CURLOPT_RETURNTRANSFER option set to true in order to return the body of the request with call to curl_exec like this:

    $url = 'http://www.farmersagent.com/Results.aspx?isa=1&name=A&csz=AL';
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    // you may set this options if you need to follow redirects. Though I didn't get any in your case
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    $content = curl_exec($curl);
    curl_close($curl);
    
    $html = str_get_html($content);
    

提交回复
热议问题