在工作中,我在大楼的另一部分有一个设备,它托管一个网页:http://10.1.1.165/
我需要解析它。
我正在尝试使用 curlpp 来检索页面,然后使用 libxml2 来解析 html。
目前我有:
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);
代码在行上中断request.peform();
输出:
terminate called after throwing an instance of 'curlpp::LibcurlRuntimeError'
what(): No URL set!
我很困惑,因为我遵循 curlpp 示例代码和此处提供的示例中完全相同的说明:https ://blog.laplante.io/2014/11/parsing-html-c-revisited/
我是否忘记设置一些设置或错误地传递了 url?