3
A
답변
9
libxml2 HTML 파서를 사용하면 "더티"HTML을 정규화 된 트리로 정규화합니다. 는
4
http://xmlsoft.org/html/libxml-HTMLparser.htmlhtmlDocPtr htmlParseFile(const char * filename, const char * encoding)
내가 인해 지식의 부족으로 너무 많은 문제에 직면 참조하십시오. 그래서 전체 데모 프로그램을 작성하여 libxml2 라이브러리를 사용하여 HTML을 구문 분석합니다.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/HTMLparser.h>
void traverse_dom_trees(xmlNode * a_node)
{
xmlNode *cur_node = NULL;
if(NULL == a_node)
{
//printf("Invalid argument a_node %p\n", a_node);
return;
}
for (cur_node = a_node; cur_node; cur_node = cur_node->next)
{
if (cur_node->type == XML_ELEMENT_NODE)
{
/* Check for if current node should be exclude or not */
printf("Node type: Text, name: %s\n", cur_node->name);
}
else if(cur_node->type == XML_TEXT_NODE)
{
/* Process here text node, It is available in cpStr :TODO: */
printf("node type: Text, node content: %s, content length %d\n", (char *)cur_node->content, strlen((char *)cur_node->content));
}
traverse_dom_trees(cur_node->children);
}
}
int main(int argc, char **argv)
{
htmlDocPtr doc;
xmlNode *roo_element = NULL;
if (argc != 2)
{
printf("\nInvalid argument\n");
return(1);
}
/* Macro to check API for match with the DLL we are using */
LIBXML_TEST_VERSION
doc = htmlReadFile(argv[1], NULL, HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET);
if (doc == NULL)
{
fprintf(stderr, "Document not parsed successfully.\n");
return 0;
}
roo_element = xmlDocGetRootElement(doc);
if (roo_element == NULL)
{
fprintf(stderr, "empty document\n");
xmlFreeDoc(doc);
return 0;
}
printf("Root Node is %s\n", roo_element->name);
traverse_dom_trees(roo_element);
xmlFreeDoc(doc); // free document
xmlCleanupParser(); // Free globals
return 0;
}
+0
또한 libxml2-2.7.8.win32를 사용했다는 사실을 사용자에게 알리고 싶습니다. –
관련 문제
- 1. void 포인터가있는 C의 일반적인 프로그래밍
- 2. C의 채팅 클라이언트? (C 네트워크 프로그래밍)
- 3. Obj c의 트리거링 방법
- 4. C의 scanf와
- 5. Objective c의 MAC OSX에서 배경색을 설정하는 방법
- 6. C의 시스템 트레이로 최소화하는 방법
- 7. 객관적인 C의 상단 막대하는 방법
- 8. C의 문자열 배열을 선언하는 방법
- 9. LLVM C의 해설이 필요합니다. 방법
- 10. 터보 C의 대안
- 11. Objective-C의 서버에서 CSV 파일을 다운로드하는 방법
- 12. C의 winMain에서 콘솔을 프로그래밍 방식으로 팝업하는 방법은 무엇입니까?
- 13. I2C 슬레이브 모드 프로그래밍 방법
- 14. C의 어떤 Dialect가 Objective-C의 "strict superset"입니까?
- 15. Objective-C의 @selector에서 발행
- 16. 나는 C의 주요 ++
- 17. 내가 같은 C의 배열을
- 18. Objective-C의 "Extension Methods"
- 19. C의 -> Objective-C의 점 표기법과 동일합니다.
- 20. (C의 객체 instanceof) C의 유형은 무엇입니까? 난
- 21. Objective C의 CLIST
- 22. C의 다른 조건이
- 23. 객관적인 - C의 이벤트에 콘센트를 연결하는 방법
- 24. macosx 로그인 방법 objective-c의 사용자 이름
- 25. C의 데이터 파일에서 열을 제거하는 방법
- 26. Google지도에서 objective-c의 GPS를 사용하는 방법
- 27. objective-c의 네트워크 연결을 확인하는 방법
- 28. 버퍼의 데이터를 C의 배열에 넣는 방법?
- 29. 리눅스에서 C의 타이머 콜백 함수를 구현하는 방법
- 30. 지수 형식을 C의 십진수 형식으로 변환하는 방법
오 ~ 유용합니다. 대단히 감사합니다.^_^ –
^^^ upvote 버튼이 바로 있습니다;) –