2016-06-12 3 views
1

모든 팀 대 팀 정보와이 URL을 사용하여 표시 버튼 아래에 숨겨진 점수를 얻으려고 시도합니다. http://www.gosugamers.net/counterstrike/teams/7397-natus-vincere/matches. 나는 opp 1 대 opp 2와 게임의 결과를 얻으려고 노력하고있다. 이것은 내가이 문제에 대해 지금까지 가지고있는 것이다.파이썬으로 아름다운 스프를 사용하여 팀 텍스트와 스코어를 얻는 방법?

def all_match_outcomes(): 

    for match_outcomes in all_match_history_url(): 
     page = requests.get(match_outcomes).content 
     soup = BeautifulSoup(page, 'html.parser') 

     for match_outcome in soup.select_one('div table.simple.gamelist.profilelist td'): 
      opp_1 = match_outcome.select_one('a').find('span') 
      print(opp_1) 
+0

당신이 지금까지 가지고 무엇을하지 무엇 코드를 보여주십시오 일. – alecxe

+0

충분히 명확합니까? 아니면 모든 코드를 추가해야합니까? – DJRodrigue

답변

2

결과가 숨겨져 범위 아래에있는 게임은 (물론, BeautifulSoup에 대한 "숨겨진"없다, 그것은 브라우저 아니다). 홈 점수는 span이고 hscore 클래스입니다. 멀리 - spanascore 클래스입니다. 팀 이름은 내부 span 내부에 요소 안에 있으며 opp1opp2 클래스가 있습니다. 구현 :

import requests 
from bs4 import BeautifulSoup 


match_outcomes = "http://www.gosugamers.net/counterstrike/teams/7397-natus-vincere/matches" 
page = requests.get(match_outcomes).content 
soup = BeautifulSoup(page, 'html.parser') 

for row in soup.select('table.simple.gamelist.profilelist tr'): 
    opp1 = row.find("span", class_="opp1").span.get_text() 
    opp2 = row.find("span", class_="opp2")("span")[-1].get_text() 

    opp1_score = row.find("span", class_="hscore").get_text() 
    opp2_score = row.find("span", class_="ascore").get_text() 

    print("%s %s:%s %s" % (opp1, opp1_score, opp2_score, opp2)) 

인쇄 :

Virtus.Pro.CS 2:1 Natus Vincere 
Dobry&Gaming; 0:2 Natus Vincere 
GODSENT 0:2 Natus Vincere 
HellRaisers 0:2 Natus Vincere 
Flipsid3 Tactics 1:2 Natus Vincere 
Natus Vincere 1:2 Dobry&Gaming; 
mousesports.CS 1:0 Natus Vincere 
mousesports.CS 0:1 Natus Vincere 
... 
Natus Vincere 2:1 Flipsid3 Tactics 
Team Dignitas.CS 0:1 Natus Vincere 
+0

두 팀 이름도 표시하려고합니다. 두 개의 span 태그가 있고 팀 텍스트는 두 번째 범위에 있습니다. 팀 이름을 어떻게 알 수 있습니까? – DJRodrigue

+0

@DJRodrigue 이미 답변이 있습니다. 10 분 전에 팀 이름을 업데이트했습니다. 희망이 도움이됩니다. – alecxe

+0

예, 죄송합니다. 새로 고침하지 않았습니다. 고맙습니다 ! – DJRodrigue

-1

보기 페이지의 소스와 당신이 필요로하는 모든 정보는 클래스 simple gamelist profilelist있는 테이블에있는 것을 볼 수 있습니다.

Beautiful Soup Documentation 과 특히 find 메소드를 읽으십시오.

봅니다 HTML 소스의 패턴을 발견하고 신속하게 각 테이블의 데이터를 반복하는 방법을 알아낼 것이다 (<td>을)과 팀 등을 추출하는 방법을

관련 문제