Не удается спарсить значение атрибута id тега article В чем моя ошибка?:
<article class="post-11632 post type-post status-publish format-standard has-post-thumbnail" id="post-11632">
<!--Здесь много вложенных блоков <div> <a> <span>, но тег <article> более не встречается-->
</article>
Парсер: Ошибка возникает при получении post_id далее все работает
import requests
import config
from bs4 import BeautifulSoup
#https://freesteam.ru/
def get_html(url):
r = requests.get(url)
return r.text
def get_free_game(html):
soup = BeautifulSoup(html, 'lxml')
card = soup.find('div', class_='row content-grid').find_all('div', class_='post-box')
for post_data in card:
#post_id, entry-title, entry-content
try:
post_id = post_data.find(class_='post type-post').get('id')
except:
post_id = ''
try:
title = post_data.find('h2', class_='entry-title').find('a').text.strip()
except:
title = ''
try:
content = post_data.find('div', class_='entry-content').find('p').text.strip()
except:
content = ''
Консоль выдает:
>>> post_id = post_data.find('article', class_='post type-post').get('id')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'get'
Предпринимал такие попытки
>>> post_id = post_data.find('article', class_='post type-post')
>>> post_id_soup = BeautifulSoup('post_id.text')
>>> post_id_soup.article['id']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable'
>>> post_id = post_data.find('span', class_='dsq-postid').get('data-dsqidentifier') >>> post_id '11632 https://freesteam.ru/?p=11632' >>> post_id_number = post_id.split(' ')[0] >>> post_id_number '11632'