提取值在一个站点上工作但不在另一个站点上工作?

时间:2015-11-24 15:44:22

标签: python

我需要你的帮助来从这个网站中提取/删除“美元指数”:Netdania's Live Streaming Currency Rates Foreign Exchange

或者此页:Netdania's Full Quote

我是Python的初学者,并尝试修改我可以在Google上找到的脚本,但没有成功。我可以使用下面的代码从其他网站获取现值(这是我需要的),但我无法将其用于上述网站。那是为什么?

# 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

0 个答案:

没有答案
相关问题