bytes 对象没有属性 find_all

bytes object has no attribute find_all

过去 3 小时我一直在尝试抓取这个 website 并获得每支球队的排名、名称、胜负。

执行此代码时:

import requests
from bs4 import BeautifulSoup

halo = requests.get("https://www.halowaypoint.com/en-us/esports/standings")

page = BeautifulSoup(halo.content, "html.parser")

final = page.encode('utf-8')

print(final.find_all("div"))

我一直收到这个 error

如果有人能帮助我,那将不胜感激!

谢谢!

您在错误的变量上调用了方法,请使用 BeautifulSoup 对象 page not 字节字符串 决赛:

print(page.find_all("div"))

获取table数据非常简单,所有数据都在div和css类[=27=中]:

halo = requests.get("https://www.halowaypoint.com/en-us/esports/standings")

page = BeautifulSoup(halo.content, "html.parser")


table = page.select_one("div.table.table--hcs")
print(",".join([td.text for td in table.select("header div.td")]))
for row in table.select("div.tr"):
    rank,team = row.select_one("span.numeric--medium.hcs-trend-neutral").text,row.select_one("div.td.hcs-title").span.a.text
    wins, losses = [div.span.text for div in row.select("div.td.em-7")]
    print(rank,team, wins, losses)

如果我们运行代码,你可以看到数据匹配table:

In [4]: print(",".join([td.text for td in table.select("header div.td")]))
Rank,Team,Wins,Losses

In [5]: for row in table.select("div.tr"):
   ...:         rank,team = row.select_one("span.numeric--medium.hcs-trend-neutral").text,row.select_one("div.td.hcs-title").span.a.text
   ...:         wins, losses = [div.span.text for div in row.select("div.td.em-7")]
   ...:         print(rank,team, wins, losses)
   ...:     
1  Counter Logic Gaming 10 1
2  Team EnVyUs 8 3
3  Enigma6 8 3
4  Renegades 6 5
5  Team Allegiance 5 6
6  Evil Geniuses 4 7
7  OpTic Gaming 2 9
8  Team Liquid 1 10