당신은 잘못된 변수에 메소드를 호출의 BeautifulSoup로 객체 페이지하지 바이트 문자열 최종를 사용 데이터는 CSS 클래스와 사업부 내에 "table.table - HCS" :
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)
코드를 실행하면 데이터가 테이블과 일치하는 것을 볼 수 있습니다.
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
유효성을 검사하기 전에이 대답을 테스트 해 봅시다! 고마워요! –
걱정하지 마시고, 멀리 시험하십시오;) –
와우, 젠체하는 말 그대로 정말 고마워. 내가 무슨 일이 있었는지 알아 내려고 화면을 쳐다 보았다고 할 때 농담이 아닙니다! 다시 한번 고마워요! '반복 블록'을 설명 할 수 있다면 더 나아질 것입니다! –