为什么下面的代码不适用于雅虎财经的股票期权

时间:2016-09-02 04:20:51

标签: python html pandas

此代码不适用于谷歌财务的雅虎财务 适用于' http://www.bloomberg.com/markets/currencies/cross-rates'

import pandas as pd
from lxml.html import parse
from urllib2 import urlopen
from pandas.io.parsers import TextParser

def _unpack(row, kind='td'):
   elts = row.findall('.//%s' % kind)
   return [val.text_content() for val in elts]

def parse_options_data(table):
   rows = table.findall('.//tr')
   header = _unpack(rows[0], kind='th')
   data = [_unpack(r) for r in rows[1:]]
   return TextParser(data, names=header).get_chunk()
parsed = parse(urlopen('https://www.google.com/finance/option_chain?q=AAPL&ouput'))

doc = parsed.getroot()
tables = doc.findall('.//table')
table = parse_options_data(tables[1])
table

我该如何解决?

0 个答案:

没有答案