繁体   English   中英

将cURL与C和非顶级URL结合使用时出现问题

[英]Problems using cURL with C and non top-level URLs

我正在使用cURL抓取网页,但似乎只能抓取顶级URL。 例如,如果我要URL URL“ http://www.businessweek.com/news/2010-09-29/flaherty-says-canada-july-gdp-report-tomorrow-may-be-negative.html ”,则不会返回任何内容(好像是空白页一样)。

这是我的C代码:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
//THIS WORKS
//curl_easy_setopt(curl, CURLOPT_URL, "news.google.com"); 

//THIS DOESN'T WORK
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.businessweek.com/news/2010-09-29/flaherty-says-canada-july-gdp-report-tomorrow-may-be-negative.html"); 
    res = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
  }
  return 0;
}

如果我能在这个问题上得到一些建议,那将是很好的。

这是因为该站点正在发送301。将CURLOPT_FOLLOWLOCATION为1以自动跟踪它们。

curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM