S
S
SHADRIN2019-02-19 23:37:00
Python
SHADRIN, 2019-02-19 23:37:00

Find_all None fails to parse what to do?

import requests
from bs4 import BeautifulSoup


def get_html(url):
  r = requests.get(url)
  return r.text


def get_all_links(html):
  soup = BeautifulSoup(html, 'lxml')	
  spans = soup.find('div', attrs = { ' class ' : 'line__wrapper ps ps--active-y' })
  span_s = spans.find_all('span', class_='line-event__name')

  links = []
   
  for span in span_s:
    a = span.find('a').get('href')
    links.append(a)
  return links


def main():
  url = 'https://betcity.ru/ru/live/soccer/' 
  all_links = get_all_links( get_html(url) )

  for i in all_links:
    print(i)


if __name__ == '__main__':
  main()

Mistake:
Traceback (most recent call last):
  File "MAIN.py", line 32, in <module>
    main()
  File "MAIN.py", line 25, in main
    all_links = get_all_links( get_html(url) )
  File "MAIN.py", line 13, in get_all_links
    span_s = spans.find_all('span', class_='line-event__name')
AttributeError: 'NoneType' object has no attribute 'find_all'

I can’t understand what to do, I just started to study parsing, and immediately the pitchfork :(
Help please
PS I already played with the classes from the bold, I thought the bs version was dumb)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AWEme, 2019-02-20
@shadrin_ss

The problem is in Javascript. All content on the site is displayed using it, and requests does not process it. At all.
This problem is solved in two ways:

  • Public API (in your case, a deaf option)
  • selenium

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question