я планирую получить данные с этого сайтомСкачивали исходный код страницы отличается от оказанного исходного кода страницы
http://www.gpw.pl/akcje_i_pda_notowania_ciagle
(это сайт основного фондового рынка в Польше)
Я у вас есть программа, написанная на C++, которая загружает источник сайта в файл. Но проблема в том, что она не содержит вещи, которые меня интересуют (ценность акций, конечно).
Если вы сравниваете этот источник сайта с опцией «Элемент просмотра» (RMB -> Элемент вида) , вы можете видеть, что элемент «Вид» содержит значения запасов.
<td>75.6</td>
<tr class="even red">
и т.д. и т.п ...
Загруженный источник сайта не имеет такой информации.
Так что у нас есть 2 вопроса
1) Почему источник сайта отличается от опции «Просмотр элемента»?
2) Как перенести мою программу так, чтобы она могла загрузить правильный код?
#include <string>
#include <iostream>
#include "curl/curl.h"
#include <cstdlib>
using namespace std;
// Write any errors in here
static char errorBuffer[CURL_ERROR_SIZE];
// Write all expected data in here
static string buffer;
// This is the writer call back function used by curl
static int writer(char *data, size_t size, size_t nmemb,
string *buffer)
{
// What we will return
int result = 0;
// Is there anything in the buffer?
if (buffer != NULL)
{
// Append the data to the buffer
buffer->append(data, size * nmemb);
// How much did we write?
result = size * nmemb;
}
return result;
}
// You know what this does..
void usage()
{
cout <<"curltest: \n" << endl;
cout << "Usage: curltest url\n" << endl;
}
/*
* The old favorite
*/
int main(int argc, char* argv[])
{
if (argc > 1)
{
string url(argv[1]);
cout<<"Retrieving "<< url << endl;
// Our curl objects
CURL *curl;
CURLcode result;
// Create our curl handle
curl = curl_easy_init();
if (curl)
{
// Now set up all of the curl options
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
// Attempt to retrieve the remote page
result = curl_easy_perform(curl);
// Always cleanup
curl_easy_cleanup(curl);
// Did we succeed?
if (result == CURLE_OK)
{
cout << buffer << "\n";
exit(0);
}
else
{
cout << "Error: [" << result << "] - " << errorBuffer;
exit(-1);
}
}
}
return 0;
}
_Как перенести мою программу так, чтобы она могла загрузить правильный код? _: Ваша программа очень близка к образцу, который поставляется с CURL ... –