Advertisement
Guest User

Nandhakumar

a guest
Feb 3rd, 2010
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # Import the BeautifulSoup parser
  2.      
  3. from BeautifulSoup import BeautifulSoup
  4.      
  5. # Import RegularExpression
  6.      
  7. import re
  8.      
  9. # This is a Python module to fetch data across WWW
  10. # More at : http://docs.python.org/library/urllib.html
  11.      
  12. import urllib
  13.      
  14. print("Start Reading the website- this may take some time - approx 2 mins ")
  15.  
  16. #open the url , read its contents into a variable
  17.      
  18. filecontent= urllib.urlopen('http://www.mjdma.com/mjdmaRatechart.aspx').read()
  19.      
  20. # convert the read contents into BeautifulSoup content
  21.      
  22. soupcontent = BeautifulSoup(filecontent)
  23.      
  24. print("Printing the values, which have been parsed")
  25.      
  26. # Create a list to store the value
  27.      
  28. gold=[ ]
  29.      
  30. # Find the extracted content that has the label named - mjdmalis_ctl
  31. # This label has the Gold rates
  32.      
  33. soup_extract = soupcontent.findAll(id= re.compile("mjdmalist_ctl[0-9]+_Label[0-9]+"))
  34.      
  35. # For loop removes the html tags from the extracted contents and appends it to
  36. # gold list
  37.      
  38. for each_soup_item in soup_extract:
  39.         gold.append(each_soup_item.find("b").contents)
  40.      
  41. # Find the length of the list
  42.      
  43. length=len(gold)
  44.      
  45. # For loop fetches the value according to the date
  46.      
  47. for i in range(length):
  48.       if (i%9==0):
  49.              print (gold[i][0])
  50.       elif((gold[i][0]).isspace()==True): # this if handles removing of whitespace
  51.              print "No Value"
  52.       else:
  53.              print eval(gold[i][0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement