首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将html数据从网站转换为熊猫数据

将html数据从网站转换为熊猫数据
EN

Stack Overflow用户
提问于 2018-05-16 02:29:52
回答 1查看 291关注 0票数 1

我想将来自网站(https://projects.fivethirtyeight.com/soccer-predictions/super-lig/)的数据输入到熊猫的数据中,但是当我尝试read_html时,我会得到以下错误:

代码语言:javascript
复制
ValueError: No tables found

下面是我使用的代码:

代码语言:javascript
复制
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from bs4 import BeautifulSoup
from urllib.request import urlopen
from selenium import webdriver
from pandas.io.html import read_html

driver = webdriver.Chrome(executable_path="C:/Users/Admin/Documents/chromedriver_win32/chromedriver")

link = "https://projects.fivethirtyeight.com/soccer-predictions/super-lig/"

driver.get(link)

table = driver.find_element_by_xpath('//*[@id="forecast-table"]')

table_html = table.get_attribute('innerHTML')

df = read_html(table_html)

以下是table_html的(部分)外观:

代码语言:javascript
复制
'<thead><tr class="desktop"><th class="top nosort"></th><th class="top bordered-right rating nosort drop-6" colspan="3">Team rating</th><th class="top bordered-right nosort drop-1" colspan="5">avg. simulated season</th><th class="top bordered-right nosort show-1 drop-3" colspan="2">avg. simulated season</th><th class="top bordered nosort" colspan="4">end-of-season probabilities</th></tr><tr class="sep"><th colspan="11"></th></tr><tr class="lower"><th class="team bold" data-tsorter="data-str">team</th><th class="num rating overall drop-6" data-tsorter="data-val">spi</th><th class="num rating offense drop-6" data-tsorter="data-val">off.</th><th class="num rating defense drop-6" data-tsorter="data-val">def.</th><th class="num wins record drop-1" data-tsorter="numeric">W</th><th class="num ties record drop-1" data-tsorter="numeric">D</th><th class="num losses record drop-1" data-tsorter="numeric">L</th><th class="num record drop-3" data-tsorter="numeric">goal diff.</th><th class="num record drop-3" data-tsorter="data-val"><span class="long-points">proj. pts.</span><span class="short-points">pts.</span></th><th class="pct drop-5" data-tsorter="data-val"><span class="full-relegated">relegated</span><span class="small-relegated">rel.</span></th><th class="pct" data-tsorter="data-val"><span class="full-champ">qualify for UCL</span><span class="small-champ">qualify for UCL</span></th><th class="pct sorted" data-tsorter="data-val"><span class="drop-1">win Süper Lig</span><span class="small-league">win league</span></th></tr></thead><tbody><tr class="team-row" data-str="Galatasaray"><td class="team" data-str="galatasaray"><div class="logo"><img src="https://secure.espn.com/combiner/i?img=/i/teamlogos/soccer/500/432.png&amp;w=56" alt="team-logo" onerror="this.onerror=null; this.src=\'https://secure.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-16 02:37:09

代码语言:javascript
复制
table_html = table.get_attribute('outerHTML')

这里,outerHTML还包括表标记

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50361640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档