速度奇快的HTML解析器 - ETPARSER 诞生了

作者开发了一款名为ETPARSER的HTML解析库,使用C语言编写,旨在提高网络爬虫的解析效率。对比Google的Gumbo-Parser,ETPARSER在相同的测试环境下速度提升了15倍,达到了每日解析1亿网页的目标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是我自己开发的一个HTML PARSER 解析库,采用C语言实现。单个进程每秒能找出200多万个URL。


HTML解析是网络爬虫或网络蜘蛛(Crawler,or Spider)的重要环节,网页中的URL就是通过HTML解析得到。
我在开发网络爬虫时,最初采用Google/Gumbo-Parser来做HTML解析器。解析1000个网页耗时大概30分钟。按照这样速度,用10台机器,每台运行10个新进程,一天(24小时)只能解析500万个网页。这样的速度我很难接受。我的目标是1天需要解析大概1亿个网页。


Google说“Gumbo-Parser已在超过25亿个来自谷歌索引的页面中进行过测试”,不知道Google是怎样测试的?使用了多少机器,花多少时间?


由于我们的钱不如Google多,不能随意买来成百上千台机器做解析。于是决定自己编写一款HTML PARSER, 看看能否提高解析的效率。凭借多年C语言编程功底,经过努力,写出来,将它取名ETPARSER。


现在可以PK了:


1. Google的工程师想很周到,速度测试工具、网页已经包含在源代码包里了。只需将
gumbo-parser/benchmarks/benchmark.cc编译就OK了。我只是加了一些说明项,重新编译并运行:

./benchmark
==== Google Gumbo-parser Search URL Result ====
bbc.html: 33832 microseconds (0.033832 seconds)
arabic_newspapers.html: 30138 microseconds (0.030138 seconds)
xinhua.html: 99877 microseconds (0.099877 seconds)
html5_spec.html: 3171881 microseconds (3.17188 seconds)
hacker_news.html: 11211 microseconds (0.011211 seconds)
wikipedia.html: 176962 microseconds (0.176962 seconds)
google.html: 96875 microseconds (0.096875 seconds)
yahoo.html: 102580 microseconds (0.10258 seconds)
-----------------------------------------------
Opened HTML Files: 8
       Read Bytes: 9.38M
      Found Links: 486370
       Time taken: 3.72336
          Average: 130627 links/second


2.而我的ETPARSER,照着benchmark.cc,写了benchmark-etparser.c,同样解析Google提供8个HTML网页。运行结果如下

./benchmark-etparser
======== ETPARSER Search URL Result ===========
bbc.html: 2631 microseconds (0.002631 seconds)
arabic_newspapers.html: 1565 microseconds (0.001565 seconds)
xinhua.html: 11873 microseconds (0.011873 seconds)
html5_spec.html: 199209 microseconds (0.199209 seconds)
hacker_news.html: 1134 microseconds (0.001134 seconds)
wikipedia.html: 12602 microseconds (0.012602 seconds)
google.html: 3576 microseconds (0.003576 seconds)
yahoo.html: 6624 microseconds (0.006624 seconds)
-----------------------------------------------
Opened HTML Files: 8
       Read Bytes: 9.38M
      Found Links: 486670
       Time taken: 0.239214 seconds.
          Average: 2034455 links/second.



我的测试环境:

  1台Thinkpad T440(Intel Core i5, RAM 4GB) 笔记本电脑上的Linux虚拟机:
         
 Linux OS:  Debian7.6.0 (Linux version 3.2.0-4)
       RAM:  1GB


总结: 

ETPARSER的解析速度比Google Gumbo-parser快15倍。1天解析1亿个网页的目标基本达到了。  其实Google很清楚它的速度问题,所以特意提示“Non-goals:Execution speed”。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值