Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: extracting from web and adding to csv file with their links

by frozenwithjoy (Priest)
on Jul 06, 2012 at 03:28 UTC ( [id://980205]=note: print w/replies, xml ) Need Help??


in reply to extracting from web and adding to csv file with their links

OK, since I'm not entirely sure what you need, perhaps you could elaborate. To start, this is the first few lines from one of the output files:

SYMBOL|NAME|LAST TRADE|CHANGE|VOLUME|RELATED INFO BAC|Bank of America Corporation Com|7.82 4:00PM EDT|0.24 (2.98%)|120,1 +61,969|Chart, Profile, More JPM|JP Morgan Chase & Co. Common St|34.38 4:02PM EDT|1.50 (4.18%)|58,5 +29,307|Chart, Profile, More SIRI|Sirius XM Radio Inc.|2.09 4:00PM EDT|0.05 (2.45%)|52,421,104|Char +t, Profile, More

Are you wanting to change "Chart, Profile, More" into "Chart, Profile, More"? If so, since you are only collecting the text and not links from the yahoo pages, your best bet is to harvest the symbols (e.g., BAC) from what you have and stick them into Yahoo's link template (e.g. http://finance.yahoo.com/q/bc?s=INSERT_SYMBOL_HERE for Charts). Assuming this is what you are trying to do, I wrote to following as a proof-of-concept and used it to replace print US $lin[1];:

for my $lin_line ( split (/\n/, $lin[1]) ) { my ( $symbol ) = $lin_line =~ m/(\w*)|/; next if $symbol eq "SYMBOL"; $lin_line =~ s|(Chart)|$1: http://finance.yahoo.com/q/bc?s=$symbol +|; } continue { print US $lin_line, "\n"; }

The output looks like:

SYMBOL|NAME|LAST TRADE|CHANGE|VOLUME|RELATED INFO BAC|Bank of America Corporation Com|7.82|Jul 5|0.24 (2.98%)|120,161,96 +9|Chart: http://finance.yahoo.com/q/bc?s=BAC, Profile, More JPM|JP Morgan Chase & Co. Common St|34.38|Jul 5|1.50 (4.18%)|58,529,30 +7|Chart: http://finance.yahoo.com/q/bc?s=JPM, Profile, More SIRI|Sirius XM Radio Inc.|2.09|Jul 5|0.05 (2.45%)|52,421,104|Chart: ht +tp://finance.yahoo.com/q/bc?s=SIRI, Profile, More

If this is what you are going for, you should elaborate on so that it reports links for 'Profile' and 'More' for all your output files.

One other thing... You are saving your files as csv, but the data you output is not comma-delimited (unless you only want 3 columns).

Replies are listed 'Best First'.
Re^2: extracting from web and adding to csv file with their links
by programmer.perl (Beadle) on Jul 06, 2012 at 17:24 UTC

    Yes, that is what I was looking for! :-) -> (I want to change "Chart, Profile, More" into "Chart link, Profile, More") It seems that my Perl script are not enough correct for the type of project... and after 2-3 years, when I'll become a master on Perl, watching my present code I will say 'how my code was comic'... I will give attention to copy-pasting code in perlmonks, Thank you for code, I added it (instead of 'print NYSE...') to my script and it is working...

      Great! Good luck on your project and feel free to send me any amazing stock trends you might uncover so I can retire and live on a sailboat.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://980205]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-24 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found