E
E
Ernest Vardanyan2020-04-23 00:50:39
Python
Ernest Vardanyan, 2020-04-23 00:50:39

Why does it give an error when parsing?

import requests
from bs4 import BeautifulSoup

URL='https://mel73157.site/live/mortal-kombat/1252965-mortal-kombat-x/'
HEADERS= {'user-agent':'Mozilla / 5.0 (Windows NT 10.0; WOW64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 80.0.3987.132 YaBrowser / 20.3.2.242 Yowser / 2.5 Safari / 537.36'}

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('div', class_='centerCon fl')
    player=[]
    for item in items:
        player.append({
            'title': item.find('div', class_='date').get_text(),
        })
    print(player)
def parse():
    html = get_html(URL)
    if html.ok:
        get_content(html.text)
    else:
        print('Ошибка в запросе')


parse()


5ea0bc21b2620095943825.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alan Gibizov, 2020-04-23
@phaggi

As I understand it, the URL page should still be opened by a regular browser. It doesn't open for me. Maybe that's why the error?
You try instead your mortalkombat to start opening a little easier.

R
Robot205, 2020-04-23
@Robot205

try with selenium

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question