【问题标题】:Problems using cURL with C and non top-level URLs将 cURL 与 C 和非顶级 URL 一起使用的问题
【发布时间】:2010-09-30 03:08:35
【问题描述】:

我正在使用 cURL 来抓取网页,但我似乎只能抓取顶级 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;
}

如果我能就这个问题获得一些意见,那就太好了。

【问题讨论】:

    标签: c url curl libcurl


    【解决方案1】:

    这是因为网站正在发送 301。将 CURLOPT_FOLLOWLOCATION 设置为 1 以自动关注它们。

    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    

    【讨论】:

      猜你喜欢
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 2021-11-08
      • 2011-04-01
      • 2016-06-26
      • 2016-02-14
      • 1970-01-01
      相关资源
      最近更新 更多