Hi,
What would be the most cool way to process/parse html and write it out
in another format, kind of transpose mode.
e.g INPUT:===============================
type
id=M_btn_Mainl00
home
clickAndWait
id=M_ct200_MainContent
Wanted output:============================
command:
command: ({ ‘type’, target: ‘id=M_btn_Mainl00’, value: ‘home’ });
command: ({ ‘clickAndWait’, target: ‘id=M_ct200_MainContent’ }); // no
value
this to compose some fancy automation libs. I see the way to basically
read and capture lines by tugs
Or maybe you have a hint how to extract value between
…
,
Tx
Dai
Depending on the formatting etc. of the real data, this could
get pretty difficult, but for your simple example data
iterating over the lines and using a regular expression
(with a named capture group) would work:
1.9.3-p194 :001 > /
(?.*?)</tr>/ =~ ’
Test
’
=> 2
1.9.3-p194 :002 > value
=> “Test”
But it certainly is not the “most cool way” and will break when
the html is formatted differently, like e.g.
Depending on the formatting etc. of the real data, this could
get pretty difficult, but for your simple example data
iterating over the lines and using a regular expression
(with a named capture group) would work:
I find processing tag structures with line oriented tools pretty uncool. In fact it’s also error prone like you state yourself:
But it certainly is not the “most cool way” and will break when
Thanks, all guys.
I"ll start with line proc I think, still not quite in oop. Thanks all
for your help, this structure is very solid, and won’t change it’s
actually Selenium scripts.html
Thanks, all guys.
I"ll start with line proc I think, still not quite in oop. Thanks all
for your help, this structure is very solid, and won’t change it’s
actually Selenium scripts.html
Sometimes a little more effort at the beginning pays off
in the long run…
See a hint for a solution using Nokogiri below.
Note that it is even simpler (in my opinion) than iterating
through lines and using regular expressions and
that it handles HTML that is more complicated than your example.
Disclaimer: I have never used Nokogiri before, and spent about
ten minutes on this, based on the simplest examples on nokogiri.org, so it’s probably wrong and/or clumsy and others
could provide much better solutions to your problem.