我打算從該網站獲得的數據不同下載頁面源比呈現的頁面源
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附帶的示例... –