HTMLページの<p><p></p></p>に囲まれた文字を取り出したいのですが、うまくできません。下記のプログラムを基に取り出せるプログラムを作りたいです。よろしくお願いします。
ーーーーーーーーーーーーーーーーーーーーーーーーー
<p class="artblock_catch">都市と自然が融合した北海道の中心地</p> <p><p>北海道の政治・経済・文化の中心地である札幌は、便利な都市機能と豊かな自然が調和している街です。国の重要文化財に指定されている「札幌市時計台」や、都市景観100選にも選ばれる「大通公園」をはじめとした観光名所も豊富で、「さっぽろ雪まつり」や「サッポロ・シティ・ジャズ」など、季節ごとのイベントもバラエティ豊か。中心部は碁盤の目状になっており、初めての人でも街歩きがしやすいのも大きな魅力です。</p> </p> </section><div class="inner"> <!--/article_blocks--> <!----> <section class="artblock_left cf"> <img class="ph" src="http://www.visit-hokkaido.jp/assets/images/feature/2015/12/2_block_image_1.jpg?1450698010" alt="" />
<!----> <div class="artblock_free"></div> <!--article_blocks/--> </div> <!--inner/-->
ーーーーーーーーーーーーーーーーーーーーーーーー
#include <libxml/HTMLparser.h>
#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
void FindInfo(xmlNode*& element);
int main() {
//HTML用の構造体
htmlDocPtr m_doc;
// ファイル名とエンコードの設定 char* file = "http://www.visit-hokkaido.jp/article/detail/2"; char* enc = "utf-8"; // xmlの読み込み if (m_doc = htmlReadFile(file, enc, HTML_PARSE_RECOVER)) { htmlNodePtr root = xmlDocGetRootElement(m_doc); if (root != NULL) { FindInfo(root); } xmlFreeDoc(m_doc); m_doc = NULL; } xmlCleanupParser(); xmlCleanupCharEncodingHandlers(); return;
}
void FindInfo(xmlNode*& element){
char* count;
for (htmlNodePtr node = element; node != NULL; node = node->next){
//<p><p>
count = (char )node->next->next->children->content;
string a = count;
printf("%s\n",count);
if(xmlStrcasecmp(node->name, (const xmlChar)"p") == 0){
for(xmlAttrPtr attr = node->properties; attr != NULL; attr = attr->next){
if(xmlStrcasecmp(node->name, (const xmlChar*)"p") == 0){
count = (char *)node->next->next->children->content;
string a = count;
printf("%s\n",count);
}
}
}
//再起読み込み if(node->children != NULL) { FindInfo(node->children); } } }