In this test model I can collect the href
value for the first ('tr', class_='rowLive')
, I've tried to create a loop to collect all the others href
but it always gives IndentationError: expected an indented block
or says I'm trying to use find
instead of find_all
.
How should I proceed to collect all href
?
import requests
from bs4 import BeautifulSoupurl = 'http://sports.williamhill.com/bet/pt/betlive/9'headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}site = requests.get(url, headers=headers)
soup = BeautifulSoup(site.content, 'html.parser')
jogos = soup.find_all('tr', class_='rowLive')jogo = jogos[0]
linksgame = jogo.find('a', href=True).attrs['href'].strip()print(linksgame)