熊猫read_html打破

时间:2019-05-31 19:28:59

标签: python pandas

我正在尝试进行抓取,当1个Ticker值没有任何信息时,过程中断。我希望它继续显示在列表中。

我尝试了不同的方法来完成这项工作。我检查了一下,雅虎网站上没有可供读取的表格。

import pandas as pd

# The 3rd Ticker value ABMD will break this code
ticker = ["MMM", "NUVR", "ABMD" "ABT"]

for tic in ticker:
    inc_state = pd.read_html('https://finance.yahoo.com/quote/' + tic + '/financials?p' + tic, na_values=['No Acquirer'])
    df = inc_state[0][2][0]
    df3 = pd.DataFrame(inc_state)
    # This if statement doesnt work ugh!
    if df != 'No Acquirer':
        print("-" * 20)
        print(tic)
        print(df)
    else:
        continue

我得到的是前两个项目都能正常工作,然后又崩溃了。

MMM

12/31/2017

NUVR 2017/12/31

Traceback (most recent call last):
  File "/Users/dfalk/Google Drive/Pycharm_Working/PythonWebScrape2/fruit.py", line 9, in <module>
    inc_state = pd.read_html('https://finance.yahoo.com/quote/' + tic + '/financials?p' + tic, na_values=['No Acquirer'])
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/io/html.py", line 1094, in read_html
    displayed_only=displayed_only)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/io/html.py", line 916, in _parse
    raise_with_traceback(retained)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/compat/__init__.py", line 420, in raise_with_traceback
    raise exc.with_traceback(traceback)
ValueError: No tables found

Process finished with exit code 1

1 个答案:

答案 0 :(得分:0)

感谢âńōŋŷxmoůŜ除了成功之外的尝试,谢谢