Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
4
Indexable
Never
from bs4 import BeautifulSoup
import requests
headers = {
    "Accept": "*/*",
    "User-Agent": "Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"
}
req = requests.get('https://dota2protracker.com/', headers=headers)
src = req.text
soup = BeautifulSoup(src, "lxml")
matches = soup.find('div', {'class': 'scroll-area'}).find_all('tr')

for m in matches:
    hero_name_elem = m.find('td', {'class': 'td-hero-pic'})
    if hero_name_elem:
        hero_name = hero_name_elem.find('a')
    else:
        continue

    if hero_name.text.strip() != 'Zeus':
        continue

    winrate_elem = m.find('td', {'class': 'td-winrate'})
    winrate = winrate_elem.find('span').text.strip() if winrate_elem else 'N/A'

    matches_played_elem = m.find('td', {'class': 'td-matches'})
    matches_played = matches_played_elem.find('div',
                                              {'class': 'perc-wr'}).text.strip() if matches_played_elem else 'N/A'

    print(hero_name.text.strip(), winrate, matches_played)