Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import the BeautifulSoup parser
- from BeautifulSoup import BeautifulSoup
- # Import RegularExpression
- import re
- # This is a Python module to fetch data across WWW
- # More at : http://docs.python.org/library/urllib.html
- import urllib
- print("Start Reading the website- this may take some time - approx 2 mins ")
- #open the url , read its contents into a variable
- filecontent= urllib.urlopen('http://www.mjdma.com/mjdmaRatechart.aspx').read()
- # convert the read contents into BeautifulSoup content
- soupcontent = BeautifulSoup(filecontent)
- print("Printing the values, which have been parsed")
- # Create a list to store the value
- gold=[ ]
- # Find the extracted content that has the label named - mjdmalis_ctl
- # This label has the Gold rates
- soup_extract = soupcontent.findAll(id= re.compile("mjdmalist_ctl[0-9]+_Label[0-9]+"))
- # For loop removes the html tags from the extracted contents and appends it to
- # gold list
- for each_soup_item in soup_extract:
- gold.append(each_soup_item.find("b").contents)
- # Find the length of the list
- length=len(gold)
- # For loop fetches the value according to the date
- for i in range(length):
- if (i%9==0):
- print (gold[i][0])
- elif((gold[i][0]).isspace()==True): # this if handles removing of whitespace
- print "No Value"
- else:
- print eval(gold[i][0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement