elkclone

stockscraper2.py

Feb 22nd, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. #!/usr/bin/python
  2. """ Your mission should you choose to accept it:... use urllib() module to
  3. scrape daily summay page source of stock symbols. write() the source pages
  4. to local files until the list len() is reached. These files can later be
  5. read() into other regex() modules or scapy() for raw data extraction
  6. Future steps---->read() a symbol list from a file or user inputed list
  7.            ---->regex() module to pluck out some image/graph data"""
  8.  
  9. import sys
  10. import os
  11. import re
  12. import urllib
  13.  
  14.  
  15. def urldog():
  16.     symbolslist = ["appl","goog","csco","intel","spy","fb"]
  17.     i=0
  18.     while i<len(symbolslist):
  19.         urlScrape = "http://finance.yahoo.com/q?s=" + symbolslist[i]+"&ql=1"
  20.         uf = urllib.urlopen(urlScrape)
  21.         x = uf.read()
  22.         f = open("goodies"+str(i)+".html","w")
  23.         f.write(x)
  24.         f.close()
  25.         uf.close()
  26.         i+=1
  27.     print "The Url's of entered stock sympols have been scraped and saved to goodie.html files"
  28.     print "These files can be later read into a regex or scapy module for data extraction. "
  29. # set up main
  30. def main():
  31.     urldog()
  32.    
  33. #call main
  34. if __name__ == '__main__':
  35.     main()
Advertisement
Add Comment
Please, Sign In to add comment