我正在尝试使用 curl 和http://www.deanclatworthy.com/imdb从 IMDB 获取电影和电视节目信息。我正在使用http://curl.haxx.se/libcurl/c/simple.html中的 simple.c 示例
cout << "Type a movie name: " << endl;
getline(cin, searchTerm);
replace(searchTerm.begin(), searchTerm.end(), ' ', '+');
CURL *curl;
CURLcode res;
string temp;
temp = "http://www.deanclatworthy.com/imdb/?q=" + searchTerm;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, temp.c_str());
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
这是我的输出,如果我搜索黑暗骑士崛起:
输入电影名称: 黑暗骑士崛起 {"imdbid":"tt1345836","imdburl":"http://www.imdb.com/title/tt1345836/","genres":"Action,Crime,Thriller" ,"languages":"English","country":"USA,UK","votes":"390735","stv":0,"series":0,"rating":"8.8","runtime" :"165min","title":"黑暗骑士崛起","year":"2012","usascreens":4404,"ukscreens":0}
我的问题是我希望将返回的带有信息的文本放入一个数组中,这样我就可以很好地整理它,例如
movieInto[14] = *array*
然后如果我想标题、评级、年份等,我可以调用数组的不同部分。它已经被格式化为一个数组,但我不知道要调用什么来进入。
希望这里聪明的头脑可以帮助我=)