Python: No tables found matching pattern '.+'

流过昼夜 提交于 2021-02-10 17:38:35

问题


I am trying to do is export this table as a CSV for all 7 pages of 100 rows each within a Python script but an running into this error below the script.

"http://www.nhl.com/stats/player?aggregate=1&gameType=2&report=points&pos=S&reportType=game&startDate=2017-10-19&endDate=2017-10-29&filter=gamesPlayed,gte,1&sort=points,goals"

import pandas as pd

dfs = pd.read_html('http://www.nhl.com/stats/player?aggregate=1&gameType=2&report=skatersummary&pos=S&reportType=game&startDate=2017-10-19&endDate=2017-10-29&filter=gamesPlayed,gte,1&sort=points,goals,assists')
df = pd.concat(dfs, ignore_index=True)
df.to_csv("1019_1029.csv", index=False)
print(df)

ValueError: No tables found matching pattern '.+'


回答1:


This site wont work with pandas.read_html. According to pandas documentation:

This function searches for <table> elements and only for <tr> and <th> rows and <td> elements within each <tr> or <th> element in the table. <td> stands for “table data”.

But site you are trying to parse uses <div> elements for structuring data into the table:

Hence, you will need custom parsing solution to read data from this site.



来源:https://stackoverflow.com/questions/47026896/python-no-tables-found-matching-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!