vet*_*982 1 c url curl libcurl
我正在使用cURL来抓取网页,但我似乎只能抓取顶级网址.例如,如果我想查询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;
}
Run Code Online (Sandbox Code Playgroud)
如果我能在这个问题上得到一些很好的意见.
这是因为该网站正在发送301.设置CURLOPT_FOLLOWLOCATION
为1以自动关注它们.
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
138 次 |
最近记录: |