@laimonsess

Почему бот отправляет не полную ссылку?

Суть заключается в том, что бот должен отправлять в ТГ канал - заглавие, описание и ссылку на пост с сайта.
Но вместо полной ссылки на пост он отправляет - /ru/post/342532/ (пример).

Вот код парсера, в чем может быть проблема?

spoiler

def parser(back_post_id):
    URL = "https://habr.com/ru/search/?q=python&target_type=posts&order=date"

    page = requests.get(URL)
    soup = BeautifulSoup(page.content, "html.parser")

    post = soup.find("article", class_="tm-articles-list__item", id=True)
    post_id = post["id"]
    
    if post_id != back_post_id:
        title = post.find("a", class_="tm-article-snippet__title-link").text.strip()
        description = post.find("p", class_="article-formatted-body article-formatted-body article-formatted-body_version-2")
        url = post.find("a", class_="tm-article-snippet__title-link", href=True)["href"]
        
        return f"{title}\n\n{description}\n\n{url}", post_id
    else:
        return None, post_id

  • Вопрос задан
  • 55 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы