0

I need your help to extract/scrape the “Dollar Index” from this website: Netdania's Live Streaming Currency Rates Foreign Exchange

Or this page: Netdania's Full Quote

I’m a beginner in Python and have tried to modify the scripts I can find with Google without success. I can use the code below to get the present value (which is what I need) from another website, but I’m not able to use it for the site mentioned above. Why is that?

# python 2.7
import urllib
import re

htmlfile = urllib.urlopen('http://finance.yahoo.com/q?s=EURUSD=X')
htmltext = htmlfile.read()

regex = '<span id="yfs_p20_eurusd=x">(.+?)</span>'
pattern = re.compile(regex)

price = re.findall(pattern, htmltext)
print price

price2 = ':'.join(price)
print price2

def get_num(x):
   return int(''.join(ele for ele in x if ele.isdigit()))

price3 = get_num(price2)
print price3
Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117
Swepy
  • 39
  • 1
  • 4
  • 3
    Instead of modifying existent scripts why don't you try to understand the ways you can achieve what you want ? – Onilol Nov 24 '15 at 15:46
  • Can you explain the code and tell us why you think it should solve your problem? Then can you explain what it is doing and how this is different from what you want it to accomplish? – Noctis Skytower Nov 24 '15 at 16:06
  • You should really consider using something like beautiful soup instead of doing regex on html. [Obligatory](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Daenyth Nov 24 '15 at 20:44
  • [**Don't use regex to parse HTML**](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – Jonathon Reinhart Nov 24 '15 at 20:48

0 Answers0