@Icarus1x9

Почему вместо ссылки выдается None?

Пытаюсь создать свой парсер, но почему-то в методе .get('href') вместо ссылки выдается слово *none*.

from bs4 import BeautifulSoup
import requests
import json
import csv
import random
from time import sleep

url = "https://it.itorrents-igruha.org"
headers = {
    "Accept": "*/*",
     "User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.5359.125 Safari/537.36"
 }
req = requests.get(url, headers=headers)
src = req.text
# print(src)

with open ("index.html", "w") as file:
     file.write(src)

with open ("index.html") as file:
    src = file.read()

soup = BeautifulSoup(src, "lxml")
all_games_hrefs = soup.find_all(class_="article-film")
# print(all_games_hrefs)

# all_games_dict = {}
for item in all_games_hrefs:
    print(item.get('href'))
    # item_text = item.text
    # item_href = item.get("href")
    # print(f"{item_text}: {item_href}")

    # all_games_dict[item_text] = item_href

# with open("all_games_dict.json", "w") as file:
#     json.dump(all_games_dict, file, indent=4, ensure_ascii=False)
  • Вопрос задан
  • 158 просмотров
Решения вопроса 1
@s4q
У article-film нет атрибута href.
Попробуйте так
for item in all_games_hrefs:
    print(item.find('a').get('href'))
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
30 апр. 2024, в 23:39
3000 руб./за проект
30 апр. 2024, в 23:32
1500 руб./за проект
30 апр. 2024, в 22:44
500 руб./в час