J
J
judywb2020-08-25 10:54:42
Python
judywb, 2020-08-25 10:54:42

Why is the VK name not parsed in the (h1) tag (python)?

I decided to master the Bs4 library Wrote a simple parser of the person's name, the name in the h1 tag, which is added to the list, empty brackets when the list is output to the console Help solve the problem, the code is below

import csv
from bs4 import BeautifulSoup
import requests
    
HOST = 'https://vk.com'
URL = 'https://vk.com/judywb'
CSV = 'mypage.csv'


def get_html(url, params = ''):
    r = requests.get(url)
    return r

def get_content(html):
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('div', class_ = 'page_info_wrap ')
    
    info = []
    for item in items:
        info.append(
            {
                'name': item.find('h1', class_ = 'page_name').get_text(),
            }
        )

    return info


def save_dock(items, path):
    with open(path, 'w', newline = ' ') as file:
        writer = csv.writer(file, delimiter = ';')
        writer.writerow(['Имя'])
        for item in items:
            writer.writerow([ item['name'] ])


def parser():
    html = get_html(URL)
    if html.status_code == 200:
        info =[]
        html = get_html(URL)
        info.extend(get_content(html.text))
        print(info)
    else:
        print('вк ебланы')

parser()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-25
@judywb

There is neither page_info_wrap nor page_name in the resulting code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question