如何使用libcurl在本地IP上获取HTML?

问题描述 投票:1回答:1

[在工作中,我在建筑物的另一部分中有一台设备,该设备托管一个网页: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?

c++ sockets libcurl curlpp
1个回答
3
投票

我得出的结论是libcurl的C ++包装器已损坏。执行curlpp :: Easy request()不起作用。我使用了C版本,一切正常:Read HTML source to string

© www.soinside.com 2019 - 2024. All rights reserved.