【发布时间】:2019-03-12 08:26:20
【问题描述】:
我想获取表格中的内容,然后将其放入以下网站中的 pandas 数据框:https://projects.fivethirtyeight.com/soccer-predictions/premier-league/
我对 BS 很陌生,但我相信我想要的是这样的:
import requests
from bs4 import BeautifulSoup
r = requests.get(url = "https://projects.fivethirtyeight.com/soccer-predictions/ligue-1/")
soup = BeautifulSoup(r.text, "html.parser")
#print(soup.prettify())
print(soup.find("div", {"class":"forecast-table"}))
但是,当然,不幸的是,这将返回“无”。任何帮助和指导都会很棒! 我相信我需要得到的东西在这里的某个地方(虽然不太确定):
<div id="forecast-table-wrapper">
<table class="forecast-table" id="forecast-table">
<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 nosort rating2" colspan="1">
</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>
【问题讨论】:
-
那么,有没有一个
div,其class 是forecast-table?
标签: python beautifulsoup