社区
C++ 语言
帖子详情
c++ html parse
Coder李海波
2007-07-24 06:10:16
有开源的c/c++的html解析器么?简单、能处理不规范的html即可。
...全文
1337
12
打赏
收藏
c++ html parse
有开源的c/c++的html解析器么?简单、能处理不规范的html即可。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
12 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
rabbit729
2007-07-25
打赏
举报
回复
不规范的怎么搞呀?学习!
jixingzhong
2007-07-25
打赏
举报
回复
用mshtml
_青云_
2007-07-25
打赏
举报
回复
可以用expat,xerces-c++,Libxml++虽然他们是用来解析XML的,不过应用于良构的HTML也应该没问题!
loops
2007-07-25
打赏
举报
回复
也许可以考虑Mozilla的engine吧,好像是Gecko吧,不过从来没用过,而且要求处理不规范的html的话,肯定会增加其复杂度的。
Tidy应该可以基本满足你的需要了吧。
Coder李海波
2007-07-25
打赏
举报
回复
to loops
linux底下,而且MSHTML COM性能不大行
loops
2007-07-25
打赏
举报
回复
使用微软的MSHTML COM组件,容错能力应该相当强。
珍惜生命远离CPP
2007-07-25
打赏
举报
回复
不规范,这个就很难了
Coder李海波
2007-07-25
打赏
举报
回复
大家用过Html tidy么?类似这样的就可以了。
kauu
2007-07-25
打赏
举报
回复
Mozilla 有
MPTD_Fire
2007-07-24
打赏
举报
回复
哪有这么好的?好像没有。
dsniff
2007-07-24
打赏
举报
回复
这个可以用正则表达式来做。下面是从boost库里的正则例子,当然你也可以用微软的正则库
The following example takes C/C++ source code as input, and outputs syntax highlighted HTML code.
#include <fstream>
#include <sstream>
#include <string>
#include <iterator>
#include <boost/regex.hpp>
#include <fstream>
#include <iostream>
// purpose:
// takes the contents of a file and transform to
// syntax highlighted code in html format
boost::regex e1, e2;
extern const char* expression_text;
extern const char* format_string;
extern const char* pre_expression;
extern const char* pre_format;
extern const char* header_text;
extern const char* footer_text;
void load_file(std::string& s, std::istream& is)
{
s.erase();
s.reserve(is.rdbuf()->in_avail());
char c;
while(is.get(c))
{
if(s.capacity() == s.size())
s.reserve(s.capacity() * 3);
s.append(1, c);
}
}
int main(int argc, const char** argv)
{
try{
e1.assign(expression_text);
e2.assign(pre_expression);
for(int i = 1; i < argc; ++i)
{
std::cout << "Processing file " << argv[i] << std::endl;
std::ifstream fs(argv[i]);
std::string in;
load_file(in, fs);
std::string out_name(std::string(argv[i]) + std::string(".htm"));
std::ofstream os(out_name.c_str());
os << header_text;
// strip '<' and '>' first by outputting to a
// temporary string stream
std::ostringstream t(std::ios::out | std::ios::binary);
std::ostream_iterator<char, char> oi(t);
boost::regex_replace(oi, in.begin(), in.end(),
e2, pre_format, boost::match_default | boost::format_all);
// then output to final output stream
// adding syntax highlighting:
std::string s(t.str());
std::ostream_iterator<char, char> out(os);
boost::regex_replace(out, s.begin(), s.end(),
e1, format_string, boost::match_default | boost::format_all);
os << footer_text;
}
}
catch(...)
{ return -1; }
return 0;
}
extern const char* pre_expression = "(<)|(>)|\\r";
extern const char* pre_format = "(?1<)(?2>)";
const char* expression_text = // preprocessor directives: index 1
"(^[[:blank:]]*#(?:[^\\\\\\n]|\\\\[^\\n[:punct:][:word:]]*[\\n[:punct:][:word:]])*)|"
// comment: index 2
"(//[^\\n]*|/\\*.*?\\*/)|"
// literals: index 3
"\\<([+-]?(?:(?:0x[[:xdigit:]]+)|(?:(?:[[:digit:]]*\\.)?[[:digit:]]+(?:[eE][+-]?[[:digit:]]+)?))u?(?:(?:int(?:8|16|32|64))|L)?)\\>|"
// string literals: index 4
"('(?:[^\\\\']|\\\\.)*'|\"(?:[^\\\\\"]|\\\\.)*\")|"
// keywords: index 5
"\\<(__asm|__cdecl|__declspec|__export|__far16|__fastcall|__fortran|__import"
"|__pascal|__rtti|__stdcall|_asm|_cdecl|__except|_export|_far16|_fastcall"
"|__finally|_fortran|_import|_pascal|_stdcall|__thread|__try|asm|auto|bool"
"|break|case|catch|cdecl|char|class|const|const_cast|continue|default|delete"
"|do|double|dynamic_cast|else|enum|explicit|extern|false|float|for|friend|goto"
"|if|inline|int|long|mutable|namespace|new|operator|pascal|private|protected"
"|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_cast"
"|struct|switch|template|this|throw|true|try|typedef|typeid|typename|union|unsigned"
"|using|virtual|void|volatile|wchar_t|while)\\>"
;
const char* format_string = "(?1<font color=\"#008040\">$&</font>)"
"(?2<I><font color=\"#000080\">$&</font></I>)"
"(?3<font color=\"#0000A0\">$&</font>)"
"(?4<font color=\"#0000FF\">$&</font>)"
"(?5<B>$&</B>)";
const char* header_text = "<HTML>\n<HEAD>\n"
"<TITLE>Auto-generated html formated source</TITLE>\n"
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=windows-1252\">\n"
"</HEAD>\n"
"<BODY LINK=\"#0000ff\" VLINK=\"#800080\" BGCOLOR=\"#ffffff\">\n"
"<P> </P>\n<PRE>";
const char* footer_text = "</PRE>\n</BODY>\n\n";
iambic
2007-07-24
打赏
举报
回复
处理不规范的HTML恰恰会增加复杂度。
htcp(给
C++
代码添加
html
标记)
如何你是一个喜欢在搜狐博客上发表
C++
技术贴的朋友,请往下看。 你是不是觉得直接将C++代码粘贴到博客上显得很不舒服,没有了已往的高亮显示,阅读代码变得很是费力,怎么样可能自动给代码加上相应的高亮显示,下面将给你提供一个简单方法。 这是我用C++写的一个linux下的小工具,称其为htcp(verson 1.0)吧(
html
cpp),这个小工具可以自动将你的C++源代码转换成可以被浏览器识别的
html
标签标记过的代码,从而为你提供一个快速的方法。 下面是该工具的源码目录, compile ------Makefile ------src.data ------res ------type.hpp ------type.cc ------
Parse
.hpp ------
Parse
.cc ------compile.cc 其中src.data是资源文件,即将你转换的代码存放进该文件 执行make命令,编译成功之后执行 ./compile > res , 将转换后的结果重定向到res文件 , Compile.cc就是主函数所在的文件. Makefile http://jinyun2012.blog.sohu.com/158883840.
html
type.hpp http://jinyun2012.blog.sohu.com/158883738.
html
?act=1283169053506 type.cc http://jinyun2012.blog.sohu.com/158883917.
html
Parse
.hpp http://jinyun2012.blog.sohu.com/158883971.
html
Parse
.cpp http://jinyun2012.blog.sohu.com/158884559.
html
compile.cc http://jinyun2012.blog.sohu.com/158884624.
html
注意在粘贴的时候请在显示源码的模式下进行,即将文本框右下方的“显示源代码“处 有问题请发邮件至jinyun2007@126.com,缙云收 博客首页http://jinyun2012.blog.sohu.com
自己用
c++
写的
html
文件解析程序(
html
-x)
程序已经更新,具体代码见: http://blog.csdn.net/sx1989827/archive/2010/02/01/5275624.aspx
JSON基础入门实战讲解
讲解JSON对象,JSON数组,JSON对象和数组的嵌套,JSON数据的修改和删除,字符串如何转JSON,JSON如何转字符串,函数JSON.
parse
,函数JSON.stringify,函数eval的使用,如何获取远程数据转JSON等
chaml:用
C++
编写的 Haml 实现
查姆 用
C++
编写的 Haml 实现。 该项目尚未完成。 安装 将此行添加到应用程序的 Gemfile 中: gem 'chaml' 然后执行: $ bundle 或者自己安装: $ gem install chaml 用法
parse
require 'chaml' CHaml .
parse
( <<HAML ) %
html
%head %title hello HAML read require 'chaml' CHaml . read ( "/path/to/haml/template.haml" ) 贡献 分叉吧 创建您的功能分支( git checkout -b my-new-feature ) 提交您的更改( git commit -am 'Add some feature' ) 推送到分支( git push origin my-n
c++
parse
html
,
C++
配置文件解析类
Parse
Config
依赖项:依赖于 ProcessString 类,可从该篇博客获取「字符串处理类 ProcessString (包含常用字符串处理函数)」
Parse
Config.h//Linux &
C++
11#pragma once//包含系统头文件#include #include #include #include //宏定义:函数参数流向#define IN#define OUT#define IN...
C++ 语言
64,654
社区成员
250,484
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章