Python parser | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python parser

Hi there! I made a simple parser that takes data from the Kinopoisk site. The parser works fine the first time but next time it doesn't. Please help, what's wrong? The code is also in my profile. import requests from bs4 import BeautifulSoup as BS """ Here is a simple parser. It takes data from the Kinopoisk website and displays only the names of films placed on the pages. Check out this code, and you will soon understand what's wrong. """ page = 1 film_number = 0 film_names_list = [] try: while True: if page == 1: page_name = None else: page_name = f"page={page}&" r = requests.get(f"https://www.kinopoisk.ru/lists/top250/?{page_name}tab=all") html = BS(r.content, "html.parser") film_names = html.find_all('p', class_="selection-film-item-meta__name") if len(film_names): for el in film_names: film_names_list.append(el.text.strip()) film_number += 1 page += 1 else: break except: print('[!] Error') print(film_names_list) print(f"Film number: {film_number}")

16th Jul 2021, 6:37 AM
Андрей Пермяков
Андрей Пермяков - avatar
2 Answers
0
u wrote a lot
19th Jul 2021, 9:26 AM
Connie Wilkins
Connie Wilkins - avatar
0
Connie Wilkins , not much
19th Jul 2021, 9:28 AM
Андрей Пермяков
Андрей Пермяков - avatar