使用 C 解析 html [英] Parse html using C

查看:27
本文介绍了使用 C 解析 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 HTML(XHTML 有效)页面中获取一些内容.我使用 curl 抓取页面并将其存储在内存中.

I need to grab some content from an HTML (XHTML valid) page. I grab the page using curl and store it in memory.

我尝试过在 PCRE 库中使用正则表达式的想法,但我找不到任何将它与 C 结合使用的示例.然后我继续查看 HTML 解析器,但仍然没有一个好的选择.我所能找到的只是一个名为 HTMLparser 的 libxml 文档模块.

I played with the idea of using regex with the PCRE library, but simply I couldn't find any examples using it with C. Then I moved on to look at HTML parsers and again there is not a good selection. All I could find was a skimpy documented module for libxml called HTMLparser.

有其他选择吗?如果没有,那么我已经找到的示例?

Are there any alternatives? If not, then examples for what I found already?

推荐答案

您想使用 HTML tidy 来做到这一点.Lib curl 页面有一些源代码可以让你继续.遍历 dom 树的文档.您不需要 xml 解析器.不会在格式错误的 html 上失​​败.

You want to use HTML tidy to do this. The Lib curl page has some source code to get you going. Documents traversing the dom tree. You don't need an xml parser. Doesn't fail on badly formated html.

http://curl.haxx.se/libcurl/c/htmltidy.html

这篇关于使用 C 解析 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆