const unsigned MAX_N_MSG = 100; unsigned found = 1; std::vector< std::string > topics; for ( unsigned msg = 1; found > 0 && msg < MAX_N_MSG; msg += found ) { const char *BASE_URL = "http://rsdn.org"; const char *START_URL = "%s/Forum/MsgList.aspx?gid=84&start=%u&flat=1&rate=0&IsFAQ=0"; char url[1024]; std::snprintf( url, sizeof(url), START_URL, BASE_URL, msg ); auto response = cpr::Get(cpr::Url{ url }); CDocument doc; doc.parse(response.text.c_str()); CSelection c1 = doc.find("html>body>form#_ctl1>table#tbl>tbody>tr"); found = 0; out << "Found " << c1.nodeNum() << " forum threads." << std::endl; for (unsigned i = 1; i < c1.nodeNum() - 1; ++i) { auto& n = c1.nodeAt(i); auto fields = n.find("td"); // #tbl > tbody:nth - child(1) > tr:nth - child(5) > td:nth - child(2..) out << "\t< "; for (unsigned fld = 0; fld < fields.nodeNum(); ++fld) { auto& f = fields.nodeAt(fld); out << f.text() << ":"; } CSelection c2 = n.find("td>b>a"); if (c2.nodeNum()) { auto& a = c2.nodeAt(0); auto& href = a.attribute("href"); auto& topic_url = std::string(BASE_URL) + href; topics.push_back( topic_url ); out << " " << topic_url; } out << " >" << std::endl; ++found; } }
Обсуждают сегодня