HTML Command Line Utilities
w3.org
w3.org
update: tracking the score of this post on the front page using this:
curl -s https://news.ycombinator.com/news | hxnormalize | hxpipe | grep -C 20 "TheZenPsycho" | grep points
-9\n pointsYour single example sells this more effectively than the entire OP. cf. http://bost.ocks.org/mike/example/
Thanks for sharing.
https://pypi.python.org/pypi/httpie/
For example: http --body https://news.ycombinator.com/news | hxnormalize ... sudo apt-get install html-xml-utils brew install html-xml-utils hxpipe (1) - convert XML to a format easier to parse with Perl or AWK
Being unfamiliar with either Perl or AWK, could anyone point me to an explanation/ example of why it is easier to parse/ what format it generates. Would it be easy to write a similar utility to say convert it to a Lua table?The following two xml documents are equivalent:
<a><b><c /></b><d>foo</d></a>
and <a>
<b> <c /> </b>
<d>foo</d>
</a>
But to understand that using classical UNIX tools which are line-oriented is quite difficult, so you'll have a hard time doing operations such as "replace 'foo' by 'bar' if it appears as the textNode of a 'd' tag".So the idea of hxpipe is that it is supposed to give you a line-oriented and similar representation of those two documents to work with.
But it actually fails to do that properly (at least for my taste). I largely prefer the output of xml2. Compare:
# first doc, output of hxpipe
(a
(b
|c
)b
(d
-foo
)d
)a
-\n
# second doc, output of hxpipe
(a
-\n
(b
-
|c
-
)b
-\n
(d
-foo
)d
-\n
)a
-\n
# output of xml2, for both documents
/a/b/c
/a/d=fooSpecifically on Mac OS X you need to modify the hxindex.c like this:
--- hxindex.c 2013-07-25 17:22:53.000000000 -0400
+++ hxindex.c.patched 2014-03-11 10:05:55.000000000 -0400
@@ -43,6 +43,7 @@
* Version: $Id: hxindex.c,v 1.20 2013-07-25 21:04:05 bbos Exp $
*
**/
+#include <sys/param.h>
#include "config.h"
#include <assert.h>
#include <locale.h>
@@ -439,7 +440,7 @@
/* Count how many subterms are equal to the previous entry */
i = 0;
- while (i < min(term->nrkeys, globalprevious->nrkeys) &&
+ while (i < MIN(term->nrkeys, globalprevious->nrkeys) &&
!folding_cmp(term->sortkeys + i, 1, globalprevious->sortkeys + i, 1))
i++;
Basically, you need the sys/param.h include and change the min function calls to MIN. --- hxindex.c.orig 2014-03-11 17:55:17.305697689 +0200
+++ hxindex.c 2014-03-11 17:58:30.331318646 +0200
@@ -103,6 +103,10 @@
#define SECNO "secno" /* Class of elements that define section # */
#define NO_NUM "no-num" /* Class of elements without a section # */
+#ifndef MIN
+# define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
+#endif
+
typedef struct _indexterm {
string url;
int importance; /* 1 (low) or 2 (high) */
@@ -435,7 +439,7 @@
/* Count how many subterms are equal to the previous entry */
i = 0;
- while (i < min(term->nrkeys, globalprevious->nrkeys) &&
+ while (i < MIN(term->nrkeys, globalprevious->nrkeys) &&
!folding_cmp(term->sortkeys + i, 1, globalprevious->sortkeys + i, 1))
i++;
I also created an Arch package with this patch:> https://dl.dropboxusercontent.com/u/127354948/arch-repo/html...
seems to work on OS X 10.9.2
wget -qO- http://fazer.se/fleminggatan -q | hxselect 'div.OrangeHeader tr' | lynx -dump -stdin