ddk1965 said:
I want to get certain data from a web page.
Example:
http://finance.yahoo.com/q?s=dow
I want to grab the number behind the field P/E -> 12.8 to a variable
in C.
Any idea to tackle this problem?
I don't want a commercial package because I need to use it in windows
& Linux.
That's a rather complex undertaking. First thing you need to
do is get the HTML text of the web page. That can't be done
with standard C, you will need some external library to do
that. Best use one that does all the work for you (perhaps
libcurl will do). Once you got that data (in a file or mem-
ory) you can use all the available string comparison func-
tions to find the bit of information you're looking for.
That can get a bit ugly since the data are rather likely
surrounded by lots of HTML tags etc. (which may even change
from time to time). Once you found the place you could use
e.g. scanf() or sscanf() to read in the number. Voila, you
are done;-)
I actually would rather not do all that in C. There are other
languages that probably will make the whole task a lot simpler
(my personal preference would probably be Perl, but there are
lots of other languages that will get the job done). If you
have a program for just the task of extracting the bit of in-
formation you need you then could start it via e.g. system()
and, when it's doen, read it what it produced from within your
C program.
BTW, some providers of such data don't allow "scraping" their
web pages, i.e. extracting information for further uses (and
some may even try to keep you from doing so by introducing
some tech- nical hurdles). I don't know if this is also the
case for Yahoo, but you should check their terms of use be-
fore you go on.
Regards, Jens