Answer the question
In order to leave comments, you need to log in
Instead of uploading data, an empty list?
Good afternoon!
For the first time I work with parsing and faced such an unpleasant problem - an empty list.
Googled and realized that the problem is frequent, but no solution at the moment has helped.
Every time it comes out or empty, for the life of me
I want to display for verification all the information with the class that appears in all blocks.
I'm due in a few hours, so I'll be glad for quick answers))
import requests
from bs4 import BeautifulSoup
from bs4.builder._htmlparser import HTMLParserTreeBuilder
URL = 'https://www.vedomosti.ru/rubrics/finance/markets'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36' , 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'}
def get_html(url, params=None):
r = requests.get(url, headers=HEADERS, params=params)
return r
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('a', class_='article-preview-item')
print(items)
def parse():
html = get_html(URL)
if html.status_code == 200:
get_content(html.text)
else:
print('Error')
parse()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question