Я следовал некоторым найденным руководствам и даже публикации на stackoverflow. После всего этого я застрял!
Дополнительная информация: это лотерейный веб-сайт, который я пытался просмотреть и проанализировать, чтобы получить счастливый номер.
Я следовал этим руководствам:
- https://towardsdatascience.com/how-to-c ... 8fad9e9ec5
- https://beautiful-soup-4.readthedocs.io/en/latest/
- Использование BeautifulSoup для поиска всех «ul» и «li» elements
from bs4 import BeautifulSoup as bs
import requests
import html5lib
#import urllib3 # another attemp to make another req in the url ------failed
url = '''https://loterias.caixa.gov.br/Paginas/Mega-Sena.aspx'''
#another try to take results in the
- but I have no qualified results == None
def parse_ul(elem):#https://stackoverflow.com/questions/503 ... i-elements
result = {}
for sub in elem.find_all('li', recursive=False):
if sub.li is None:
continue
data = {k: v for k, v in sub.attrs.items()}
if sub.ul is not None:
# recurse down
data['children'] = parse_ul(sub.ul)
result[sub.li.get_text(strip=True)] = data
return result
page = requests.get(url)#taking info from website
print(page.encoding)# == UTF-8
soup = bs(page.content,features="lxml")#takes all info from the url and organizes it ==Beaultiful soup
numbers = soup.find(id='ulDezenas')#searcher in the content of this specific id// another try: soup.find('ul', {'class': ''})
result = parse_ul(soup)#try to parse info, but none is found EVEN WITH THE ORIGINAL ONE
print(numbers)#The result is below:
''' - {{dezena.length > 2 ? dezena.slice(1) : dezena}}
print(result)# == "{}" nothing found
#with open('''D:\Documents\python\_abretesesame.txt''', 'wb') as fd:
# for chunk in page.iter_content(chunk_size=128):
# fd.write(chunk)
# =======printing document(HTML) in file still no success in getting the numbers
Подробнее здесь: https://stackoverflow.com/questions/717 ... utifulsoup