Skip to content

Instantly share code, notes, and snippets.

@AlgorithmAlchemy
Last active June 29, 2023 10:43
Show Gist options
  • Save AlgorithmAlchemy/7598d6fe02cf64e1c0991d9e55c7055f to your computer and use it in GitHub Desktop.
Save AlgorithmAlchemy/7598d6fe02cf64e1c0991d9e55c7055f to your computer and use it in GitHub Desktop.
Simple Vk htlml page friend parser
from bs4 import BeautifulSoup
# Открываем HTML-файл
with open('file.html', 'r', encoding='utf-8') as file:
html_content = file.read()
# Создаем объект BeautifulSoup для парсинга
soup = BeautifulSoup(html_content, 'html.parser')
# Находим все блоки с классом "Friends__item"
friend_items = soup.find_all('div', class_='Friends__item')
# Обрабатываем каждый блок
for friend_item in friend_items:
# Извлекаем ссылку на профиль
profile_link = friend_item.find('a')['href']
# Извлекаем ID пользователя
user_id = profile_link.split('/')[-1]
# Выводим ссылку на профиль и ID пользователя
print("Ссылка на профиль:", profile_link)
print("ID пользователя:", user_id)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment