Leser: 3
![]() |
|< 1 2 3 >| | ![]() |
23 Einträge, 3 Seiten |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#!/usr/bin/perl use strict; use warnings; use Web::Scraper; my $content = do{ local $/; <DATA> }; my $parser = scraper{ process 'tr', 'elements[]' => scraper{ process 'input[type="checkbox"]', 'Ladung' => '@value'; process 'tt', 'infos[]' => 'TEXT'; }; }; my $result = $parser->scrape( $content ); for my $element ( @{ $result->{elements} } ){ my ($ladung) = $element->{Ladung} =~ m!,(.*?)\)!; my ($scan) = $element->{Ladung} =~ m!FinneganScanNumber%3a%20(\d+)!; my ($massobs,$massexp,$masscalc,$info) = @{ $element->{infos} }[1,2,3,-1]; my ($seq,$mod) = split /\s*\+\s*/, $info; print qq~ Ladung: $ladung FinneScanNumber: $scan Mass Observed: $massobs Mass exp: $massexp Mass calc: $masscalc Sequence: $seq Modification: $mod ~; } __DATA__ <TR> <TD align=right><INPUT type=checkbox CHECKED value="1060.542634 from(531.278593,2+) title(Elution%20from%3a%20777%2e777%20to%20777%2e777%20period%3a%20dimer_02%2eraw%20experiment%3a%201%20cycles%3a%201%20precIntensity%3a%2080142%2e0%20FinneganScanNumber%3a%203539) query(5104)" name=QUE></TD> <TD align=right><TT><A onmouseover="statusString = h1_q5104; if (!browser_EXCLUDE) activateEl('Q5104', event)" onmouseout=clearEl() href="http://test.de" target=_blank>5104</A> </TT></TD> <TD align=right><TT><FONT color=#ff0000><B>531.27859 </B></FONT></TT></TD> <TD align=right><TT><FONT color=#ff0000><B>1060.54263 </B></FONT></TT></TD> <TD align=right><TT><FONT color=#ff0000><B>1060.54001 </B></FONT></TT></TD> <TD noWrap align=right><TT><FONT color=#ff0000><B>0.00263 </B></FONT></TT></TD> <TD align=right><TT><FONT color=#ff0000><B>0 </B></FONT></TT></TD> <TD noWrap align=right><TT><FONT color=#ff0000><B>(19) </B></FONT></TT></TD> <TD noWrap align=right><TT><FONT color=#ff0000><B>2.4 </B></FONT></TT></TD> <TD align=right><TT><FONT color=#ff0000><B>1 </B></FONT></TT></TD> <TD noWrap><TT><FONT color=#ff0000><B>R.TLLEGEESR.M + di-MetCarboxylation (R)</B></FONT></TT></TD></TR>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/perl use strict; use warnings; print "wait please, program running!!!\n "; use HTML::TreeBuilder; my $tree = HTML::TreeBuilder->new; $tree->parse_file('C:/Documents and Settings/Mittler/Desktop/test.html'); #diese test.html enthält viele blöcke von TR, und welche auch ohne 'INPUT' tag du kannst es erstellen in dem du der TR block pastest und kannst auch welche modifizieren in dem du z.B INPUT tag weg lässt. my @table_rows = $tree->look_down( '_tag' => 'tr', sub { #da tut nicht was ich will?? das der input tag miteibezogen wird $_[0]->look_down ( '_tag' => 'input',) sub { #die sub tut s wenn die obere sub weg lass, aber bricht ab wenn ein TR block ohne INPUT tag auftaucht, und genau das möchte ich nicht. $_[0]->look_down ( '_tag' => 'tt', sub { $_[0]->as_text =~ /Met/ }) }} ) ); foreach my $table_row (@table_rows) { my($input_field) = $table_row->look_down('_tag' => 'input'); print $input_field->attr('value'), "\n"; foreach my $input_text ($table_row->look_down('_tag' => 'tt')){ #print $input_text->as_text; my @array = $input_text->as_text; print "$array[0]\n"; # <---kann ich da diese werte splitten und einzelen ausgeben? } print"----------------------------------------------\n"; } print "done!\n"
Gast+2007-11-05 19:37:14--danke erstmal;
ich habe mir dein code angeschaut,
ich habe folgende frage,
kann ich die <DATA> durch einen Pfad ersetzen, weil ich habe eine Html-Datei auf der Festplatte mit text usw..und enthält diese TR Blöcke, ich kann s nicht im code pasten das ist zugross;
my $content = do{ local (@ARGV,$/) = '/pfad/zur/datei'; <> };
my $content = do{ local $/; <DATA> };
Quoteund was anderes:_) gibts ein manual oder howto für Web::Scraper?,
Quoteweil ich da nicht nachvollziehen kann was du mir gepostet hast.
welche Variante an code wäre besser?? deins oder meins??effizienz??speicher??
Quoteschau mal diesen code da bestele ich an ihn rum;
ich danke dir wegen deiner Betreuung; so fühlt man sich besser.
[... code ... ]
![]() |
|< 1 2 3 >| | ![]() |
23 Einträge, 3 Seiten |