I am trying to build a programm that gets the lottery result and put the 6 numbers into a list, so I will be able to compare it with other lists with from an excel sheet which I already imported using pandas. However, I am new in web scraping and I came to a point where I do not know why is not working and how to solve the errors. I already wrote the pandas and dataframe parts in another programm, so I only need help with extracting the text and converting it into a list.
Here is my code below:
import requests
from bs4 import BeautifulSoup
import pandas as pd
import re
import math
url = 'https://loterias.caixa.gov.br/Paginas/Mega-Sena.aspx'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like `Gecko) Chrome/115.0.0.0 Safari/537.36'}
site = requests.get(url, headers=headers)
soup = BeautifulSoup(site.content, 'html.parser')
resultado = soup.find('ul', class_=re.compile('resultado.listaDezenas'))
listafinal=[]
for result in resultado.find_all('li', class_=re.compile('ng-scope')):
result = result.get_text().strip()
listafinal.append(result)
print (listafinal)
And here is the error message:
urllib3 (2.0.4) or chardet (5.2.0)/charset_normalizer (3.2.0) doesn't match a supported version!
warnings.warn(
Traceback (most recent call last):
File "c:Projetos_Python\testando.py", line 16, in <module>
for result in resultado.find_all('li', class_=re.compile('ng-scope')):
AttributeError: 'NoneType' object has no attribute 'find_all'```
Thanks for the help in advance!