Jump to content

Web scraping to get stock info

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
ahdrage

ahdrage

    Newbie

  • Members
  • Pip
  • 7 posts
Hi!
Im trying to get a better overview of my portfolio. So im trying to make a script to make it happen.

The script should take the ticker info from this website: http ://bors.e24.no/e24.no/site/stock/stock_detail.page?magic=(cc%20(detail%20(tsid%2053786))) (example stock)
Once I retrieve the information I want to use it on my homepage to automaticly calculate what my portfolio is worth.

Could anyone point me in the right direction of what I need to do?

#2
TkTech

TkTech

    The Crazy One

  • Moderators
  • 1,396 posts
You could always post a job in the freelancer section, and someone could write the program for you.

Otherwise, the easiest way would be to go with PHP and use regex to parse what you needed from the page.

#3
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Yea just grab the page (ton of functions to do this) then use some regular expressions to get the information you needed from this, i'd probably try and find a rss feed that makes it a ton easier to use this information.

#4
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
I would use wget or Lynx,
but you could also use curl, file_get_contents or fopen
depends on your environment and what you know.

Good Luck :)

#5
ahdrage

ahdrage

    Newbie

  • Members
  • Pip
  • 7 posts
Thanks for your suggestions guys. I will look into all of them. I've done some programming before, but don't have a lot of experience. But I like a challenge :)

I now used firebug to find where in the sourcecode the price of the stock comes from. If you open the link I gave in the first post, the stock price comes in the <H1> tag.
So I could forexample use regex to get the price from the <H1> tag?

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
yes.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
seagulf

seagulf

    Newbie

  • Members
  • Pip
  • 1 posts
Have you tried irobotsoft web scraper? You really don't need much programming skill to make it work.

#8
JenniC

JenniC

    Newbie

  • Members
  • Pip
  • 6 posts
Biterscripting is one scripting language you ought to try if you are downloading stock quotes and doing further processing. I wrote a quick script for you. Let's say you have 70 shares of IBM and 80 shares of MSFT.



#Script portfolio.txt


var real price, value, total

var str data


# Get IBM data.

script ss_webpagetocsv.txt page("http: //finance.yahoo.com/q?s=IBM") number(1) > $data

lex "1" $data > $data ; wex "1" $data > $data

set $price = makereal(str($data))

set $value = $price * 70

set $total = $total + $value

echo "IBM: " $price " " $value " " $total


# Get MSFT data.

script ss_webpagetocsv.txt page("http: //finance.yahoo.com/q?s=MSFT") number(1) > $data

lex "1" $data > $data ; wex "1" $data > $data

set $price = makereal(str($data))

set $value = $price * 80

set $total = $total + $value

echo "MSFT: " $price " " $value " " $total


# Show portfolio value.

echo "Portfolio: $" $total "    *** Congratulations ***"



I have tested this script. It shows me

Quote

IBM: 123.18 8622.60 8622.60
MSFT: 26.64 2131.20 10753.80
Portfolio: $10753.80 *** Congratulations ***

As I mentioned, script is in biterscripting. To try, save the above script in file C:/Scripts/portfolio.txt, start biterscripting. Then enter the following command.

script "C:/Scripts/portfolio.txt"

You should see the same results. The stock symbols and share counts can be read from a file or spreadsheet, instead of hardcoding.

(Sorry, I could not work with e24.no. I could not understand the language so I did not know which number meant what. For example, if the number 123.18, meant last trade, average price, low, high or what.)

Jenni

#9
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
With so many mature, proven FOSS scripting languages/environments
out there, why use an unproven obscure commercially licensed language/environment.

free trial license??? :thumbdown:

#10
Carly Fiorina

Carly Fiorina

    Newbie

  • Members
  • Pip
  • 1 posts
thats great