0

мне нужно парсером получить заголовки новостей и ссылку на полную статью как получить выделенную ссылку?

import requests
from bs4 import BeautifulSoup as bs

spis = []
spis2 = []
sesssion = requests.Session()

new = requests.get('https://www.vesti.ru/news')
html = bs(new.content, 'html.parser')

count = 0

for i in html.select('.b-item__info'):
    title2 = i.select('.b-item__title > a')
    spis.append(str(title2))
for j in spis:
    string = list(j)
    d = string[32:-5]
    spis2.append(''.join(d))
for i in spis2:
    print(i)


4
  • qna.habr.com/q/598214
    – Nobody
    10 мая 2020 в 18:48
  • @Nobody спасибо большое 10 мая 2020 в 18:54
  • не забудьте пометить ответ галочкой , который вам помог
    – Nobody
    10 мая 2020 в 23:02
  • @Nobody никакой 10 мая 2020 в 23:04

2 ответа 2

0

Как сказано в гугле:

for link in soup.find_all('a'): print(link.get('href'))

0
import requests, bs4
new = requests.get('https://www.vesti.ru/news')
for container in bs4.BeautifulSoup(new.content, 'html.parser').find_all('div', attrs={'class': 'b-item__info'}):
    if 'https://russia.tv' in container.a['href']:
        print(container.a.text)  # Итоги шестого конкурсного дня шоу "Танцы со звездами": сильнейшие Денис Тагинцев - Екатерина Варнава

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.