从HTML表中提取文本 [英] Extract text from HTML Table
本文介绍了从HTML表中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从表格 http://www.amiriconstruction.co中提取文本从Mac OS X命令行中将.uk/goodwoodgolf/scoretable.htm 制成纯文本格式的纺织品,而没有html标签.
I want to extract the text from the table http://www.amiriconstruction.co.uk/goodwoodgolf/scoretable.htm into a textile in plain text without html tags from the Mac OS X command line.
我尝试了很多sed命令,但是sed只会再次打印整个文件.我在做什么错了?
I tried a lot of sed commands, but sed will only print the whole file again. What am I doing wrong?
我尝试过的例子
sed -n '/<tr>/,/<\/tr>/p' scoretable.htm
(只会打印带有html标记:()
sed -n '/<tr>/,/<\/tr>/p' scoretable.htm
(will just print table contents with html tags :( )
推荐答案
在wget
的帮助下,抓取一些TXR Web网页:
A little TXR web scraping, with the help of wget
to grab the page:
@(deffilter nobr ("<br />" ""))
@(deffilter brsp ("<br />" " "))
@(deffilter nosp (" " ""))
@(next "!wget 2>/dev/null -O - http://www.amiriconstruction.co.uk/goodwoodgolf/scoretable.htm")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@(skip)
<div class="scoreTableArea">
@(collect)
<h2 class="unify">@year - @event</h2>
@ (filter brsp event)
@ (collect)
<tr>
<td class="center">@pos</td>
<td>@player</td>
<td>@company</td>
<td>@date</td>
<td class="center">@points</td>
</tr>
@ (filter nobr player company date points)
@ (filter nosp pos points)
@ (until)
</tbody>
@ (end)
@(end)
@(output :filter :from_html)
@ (repeat)
Event: @event
Year: @year
DATE POS PT PLAYER COMPANY
@ (repeat)
@{date -10} @{pos -2} @{points 2} @{player 16} @company
@ (end)
@ (end)
@(end)
样品运行:
$ txr scoretable.txr
Event: Teeing off to Clobber Ken
Year: 2011
DATE POS PT PLAYER COMPANY
Sept 2011 1 40 John Durrant King Sumners Partnership
Sept 2011 2 34 Grahame Pettit Amiri Construction
Oct 2011 3 31 Tony Deacon Gleeds
Oct 2011 4 29 Tony Boyle Lacey Hickey Caley
Oct 2011 5 29 Richard Hemming Scott White and Hookins
Sept 2011 6 29 Ian McCoy Selway Joyce
June 2011 7 27 Julian Larkin C&G Properties
Sept 2011 8 25 Roque Menezes Capita Symonds
June 2011 9 22 Shawn Lambert PWP Architects
Sept 2011 10 22 Kevin Lendon Amiri Construction
Event: Ken Watson (HNW Architects) Undisputed Amiri Golf Demon of the Downs
Year: 2010
DATE POS PT PLAYER COMPANY
2010 1 40 Ken Watson HNW Architects
2010 2 37 David Heda London Clancy
2010 3 34 Gordon Brown Currie & Brown
2010 4 32 Alistair Taylor Wildbrook Properties
5 30 Andy Goodridge City Estates
6 25 Russ Pitman Henderson Green
7 24 Phil Piper Piper Whitlock
8 23 Kevin Miller Urban Pulse Architects
9 19 Simon Asquith Godsall Arnold Partnership
10 19 Shawn Lambert PWP Architects
11 18 Martin Judd Davis Langdon
这篇关于从HTML表中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文