Ich habe 2 verschiedene Versionen, eine funktioniert, eine nicht. Jedoch ist die funktionierende Version sehr unübersichtlich.
FUNKTIONIERENDE:
PHP Code:
#include <curl\curl.h>
#include <string>
#include <regex>
#include <iostream>
void einloggen(CURL *curl);
void sammeln(CURL *curl);
void verkaufen(CURL *curl);
void leeren(CURL *curl);
void activities(CURL *curl, std::string *activSource);
static size_t WriteCallBack(void *contents, size_t size, size_t nmemb, void *userp);
int main()
{
CURL *curl;
std::string activSource, activSourceReg;
std::regex activ1("(counter)(\\()(.*)(\\d+)(,\"/activities/\")");
std::regex activ2("(counter)(\\()");
std::regex activ3("(,\"/activities/\")");
std::smatch matched;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://www.pennergame.de/login/check/");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "username=XXX&password=XXX&submitForm=Login");
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
curl_easy_perform(curl);
curl_easy_reset(curl);
curl_easy_setopt(curl, CURLOPT_URL, "http://www.pennergame.de/activities/");
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallBack);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &activSource);
curl_easy_perform(curl);
curl_easy_reset(curl);
std::regex_search(activSource, matched, activ1);
activSourceReg = matched[0];
std::cout << activSourceReg << std::endl;
activSourceReg = std::regex_replace(activSourceReg, activ2, "");
std::cout << activSourceReg << std::endl;
activSourceReg = std::regex_replace(activSourceReg, activ3, "");
std::cout << activSourceReg;
std::cin.get();
}
}
static size_t WriteCallBack(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
NICHT FUNKTIONIERENDE:
PHP Code:
#include <curl\curl.h>
#include <string>
#include <regex>
#include <iostream>
void einloggen(CURL *curl);
void sammeln(CURL *curl);
void verkaufen(CURL *curl);
void leeren(CURL *curl);
void activities(CURL *curl, std::string *activSource);
static size_t WriteCallBack(void *contents, size_t size, size_t nmemb, void *userp);
int main()
{
CURL *curl;
std::string activSource, activSourceReg;
std::regex activ1("(counter)(\\()(.*)(\\d+)(,\"/activities/\")");
std::regex activ2("(counter)(\\()");
std::regex activ3("(,\"/activities/\")");
std::smatch matched;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl)
{
einloggen(&curl);
activities(curl, &activSource);
std::regex_search(activSource, matched, activ1);
activSourceReg = matched[0];
std::cout << activSourceReg << std::endl;
activSourceReg = std::regex_replace(activSourceReg, activ2, "");
std::cout << activSourceReg << std::endl;
activSourceReg = std::regex_replace(activSourceReg, activ3, "");
std::cout << activSourceReg;
std::cin.get();
}
}
void einloggen(CURL *curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://www.pennergame.de/login/check/");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "username=XXX&password=XXX&submitForm=Login");
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
curl_easy_perform(curl);
curl_easy_reset(curl);
}
static size_t WriteCallBack(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
void activities(CURL *curl, std::string *activSource)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://www.pennergame.de/activities/");
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallBack);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &activSource);
curl_easy_perform(curl);
curl_easy_reset(curl);
}
Liegt es an den Cookies oder so? Weil mein Fenster bleibt leer, und bei der ersten Version erhalte ich die gewünschte Regex Info.
Außerdem werde ich bei weiterm probieren mit Zugriffsverletzungen zubombardiert :/