Portál AbcLinuxu, 10. května 2025 02:41
S elinksem jsem tez neuspel, muzete me nekdo nakopnout s tim sedem, awkem a dalsimi kamarady?Jak neuspěl? Já toto zkusil :
elinks -dump-width 150 -dump http://www.ebanka.cz/Firemni-finance/Firemni-ucet/Transparentni-ucet/trAccountDetail.jsp?accountNumber=2588438001a obdržel jsem pěkný textový výpis, který už by neměl být problém dále zpracovávat ve skriptu (za pomoci potřebných programů, jako sed, grep, sort, ......) a dovést ho do potřebné struktury.
xmllint
?
<?php
$string = strstr(file_get_contents ('dataget2'), '<tbody>');
$pozice = strpos ($string, '</tbody>');
$string2 = substr ($string, 0, $pozice);
#$string3 = html_entity_decode ($string2);
$dopryc = array(" class=\"odd\"", " class=\"even\"", "\n", " ", "<tbody>", " ", "td", "br");
$string3 = str_replace($dopryc, "", $string2);
$string4 = str_replace("</tr>", "</tr>\n", $string3);
$dopryc = array("<", ">", "tr");
$string5 = str_replace($dopryc, "", $string4);
$string6 = str_replace("/", ";", $string5);
$dopryc = array(";;;;;;", ";;;;;", ";;;", ";;");
$string7 = str_replace($dopryc, ";", $string6);
echo $string7;
?>
Zdenek
use HTML::TableExtract;
a přes něj se pak dá (mj.):
Datum: 2007-01-05 04:21:39.0 Variabilni symbol: 28 Castka: 400.00 Datum: 2007-01-03 05:35:26.0 Variabilni symbol: 5 Castka: 400.00 Datum: 2007-01-03 05:35:23.0 Variabilni symbol: 33 Castka: 400.00 Datum: 2007-01-03 05:33:14.0 Variabilni symbol: 51 Castka: 800.00 Datum: 2007-01-02 09:36:02.0 Variabilni symbol: 16 Castka: 400.00 Datum: 2007-01-02 05:57:28.0 Variabilni symbol: 49 Castka: 400.00 Datum: 2007-01-01 23:59:59.0 Variabilni symbol: Castka: Datum: 2006-12-31 23:59:59.0 Variabilni symbol: Castka: 0.04 Datum: 2006-12-28 06:40:52.0 Variabilni symbol: 8 Castka: 400.00 Datum: 2006-12-28 05:48:15.0 Variabilni symbol: 48 Castka: 400.00 Datum: 2006-12-20 17:57:35.0 Variabilni symbol: Castka: 1000.00Navíc je použita primitivní cache, která stáhne zdrojový kód z netu jen tehdy, pokud ho nenajde již dříve uložený na disk (což se hodí při ladění).
#!/usr/bin/env python import urllib2 from HTMLParser import HTMLParser class MyHTMLParser(HTMLParser): def parse(self, html): self.tdcounter = 0 self.within_tbody = False self.thead_found = False self.platby = [] self.platba_parsed = [] self.feed(html) self.close() def handle_starttag(self, tag, attrs): if tag == 'td': self.tdcounter += 1 if tag == 'tbody' and self.thead_found: self.within_tbody = True def handle_data(self, data): if 'VARIABIL' in data: self.thead_found = True if self.within_tbody: if self.tdcounter in (4,13,17): self.platba_parsed.append(data.strip()) def handle_startendtag(self, tag, attrs): if self.within_tbody and tag == 'br': self.tdcounter += 1 def handle_endtag(self, tag): if tag == 'tr': self.tdcounter = 0 if self.platba_parsed: self.platby.append(self.platba_parsed) self.platba_parsed = [] if tag == 'tbody': self.within_tbody = False url = 'http://www.ebanka.cz/Firemni-finance/Firemni-ucet/Transparentni-ucet/trAccountDetail.jsp?accountNumber=2588438001' htmlcache = 'ebanka_cache' try: contents = file(htmlcache).read() except: handler = urllib2.urlopen(url) contents = handler.read() handler.close() file(htmlcache, 'w').write(contents) parser = MyHTMLParser() parser.parse(contents) for datum, varsymb, castka in parser.platby: print 'Datum: %s Variabilni symbol: %s Castka: %s'%( datum, varsymb, castka)
// ==UserScript== // @name eBanka // @description eBanka // @include http://www.ebanka.cz/Firemni-finance/Firemni-ucet/Transparentni-ucet/trAccountDetail.jsp* // ==/UserScript== function lTrim(value) { var r = /\s*((\S+\s*)*)/; return value.replace(r, "$1"); } function rTrim(value) { var r = /((\s*\S+)*)\s*/; return value.replace(r, "$1"); } function trim(value) { return lTrim(rTrim(value)); } window.addEventListener( 'load', function() { var table, tbody, rows, columns, items, txt; txt = ""; line = new Array(16); table = document.getElementsByTagName('table')[0]; if (!table) { alert('Nemôžem nájsť <table>'); return; } tbody = table.getElementsByTagName('tbody')[0]; if (!tbody) { alert('Nemôžem nájsť <tbody>'); return; } rows = tbody.getElementsByTagName('tr'); for (var i = 0; i < rows.length; i++) { row = rows[i]; columns = row.getElementsByTagName('td'); if (columns.length != 7) { alert('Zlý počet stĺpcov:' + columns.length); return; } items = columns[0].textContent.split('\n'); line[0] = items[1]; // poradove cislo items = columns[1].textContent.split('\n'); line[1] = items[1]; // datum line[2] = items[2]; // cas items = columns[2].textContent.split('\n'); line[3] = items[1]; // poznamka line[4] = items[2]; // nazov uctu line[5] = items[3]; // cislo uctu items = columns[3].textContent.split('\n'); line[6] = items[1]; // datum odpisania line[7] = items[2]; // valuta line[8] = items[3]; // typ items = columns[4].textContent.split('\n'); line[9] = items[1]; // variabilny symbol line[10] = items[2]; // konstantny symbol line[11] = items[3]; // specificky symbol items = columns[5].textContent.split('\n'); line[12] = items[2]; // ciastka items = columns[6].textContent.split('\n'); line[13] = items[1]; // poplatok line[14] = items[2]; // zmena line[15] = items[3]; // spr8va for (var k = 0; k < line.length; k++) { line[k] = trim(line[k]); } txt += line.join(";") + "<br>\n"; } document.open() document.writeln(txt + "<br>"); document.close(); }, true);
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.