1

At work, I have a device in another part of the building, which hosts a web page: http://10.1.1.165/ which I need to parse.

I am attempting to use curlpp to retrieve the page and then libxml2 to parse the html.

Currently I have:

curlpp::Easy request;
request.setOpt(curlpp::options::Url(std::string("http://10.1.1.165/")));
std::list<std::string> headers;
headers.push_back(HEADER_ACCEPT);
headers.push_back(HEADER_USER_AGENT);
std::ostringstream responseStream;
curlpp::options::WriteStream streamWriter(&responseStream);
request.setOpt(streamWriter);
request.perform();
std::string re = responseStream.str();
htmlDoc = htmlReadDoc((xmlChar*)re.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING);

The code breaks on the line request.peform(); The output:

terminate called after throwing an instance of 'curlpp::LibcurlRuntimeError'
  what():  No URL set!

I am very confused as I am following pretty identical instructions from the curlpp example code and an example provided here: https://blog.laplante.io/2014/11/parsing-html-c-revisited/

Am I forgetting to set some settings or incorrectly passing the url?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
B. Hoeper
  • 216
  • 3
  • 12

1 Answers1

3

I have come to the conclusion that the C++ wrapper for libcurl is broken. Performing a curlpp::Easy request() does not work. I used the C version and everything works fine: Read HTML source to string

B. Hoeper
  • 216
  • 3
  • 12
  • I was going to suggest that, and then thought that was kind of a shitty non-answer to your question. But...The C++ wrapper is entirely superfluous imo, except for FURTHER wrapping (Python/C#, etc) – zzxyz Dec 19 '19 at 23:23
  • Can you describe what is broken about it, to make this answer more complete? – nanofarad Dec 20 '19 at 18:53