Issue
How to ignore the <span class="label-negative"
and get text percent value in <span style="color: #3F8539">
and #A9CF54
?
#url = 'https://www.dotabuff.com/heroes/trends'
cont = soup.find_all("td", attrs = {"r-tab r-group-1 cell-centered"})
cont
Solution
To load the table from the site I recommend to use pd.read_html()
:
from io import StringIO
import pandas as pd
url = "https://www.dotabuff.com/heroes/trends"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0"
}
df = pd.read_html(StringIO(requests.get(url, headers=headers).text))[0]
df = (
df.droplevel(0, axis=1)
.set_index(("Unnamed: 0_level_1", "Hero"))
.rename_axis(index=None)
)
print(df.head(10))
Prints:
Win Rate Pick Rate
Start Current Change Trend Start Current Change Trend
Shadow Demon 46.33% 48.10% +1.78% NaN 2.07% 2.37% +0.30% NaN
Ember Spirit 49.38% 51.00% +1.62% NaN 5.75% 7.08% +1.32% NaN
Bane 49.85% 51.15% +1.30% NaN 2.46% 2.85% +0.39% NaN
Chen 46.70% 47.72% +1.03% NaN 1.02% 0.96% -0.05% NaN
Nature's Prophet 48.47% 49.45% +0.98% NaN 16.80% 17.30% +0.50% NaN
Troll Warlord 50.77% 51.73% +0.96% NaN 5.37% 5.17% -0.20% NaN
Lone Druid 51.32% 52.28% +0.96% NaN 3.05% 3.13% +0.08% NaN
Disruptor 49.34% 50.25% +0.91% NaN 5.86% 6.13% +0.27% NaN
Viper 52.77% 53.59% +0.82% NaN 12.99% 13.84% +0.86% NaN
Lina 45.89% 46.65% +0.75% NaN 13.83% 13.81% NaN NaN
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.