0

мне нужно написать парсер который будет парсить статьи и комментарии к ним, но при парсинге ссылок выводит none и я не знаю как это исправить. Помогите пожалуйста.

from bs4 import BeautifulSoup as bs
import requests 

articles = {}

url = 'https://lainelir2.pythonanywhere.com/'
r = requests.get(url)
soup = bs(r.text, 'lxml')

articles_title = soup.find_all('div', class_='container-link')

for item in articles_title:
    item_text = item.text
    item_href = item.get('href')
    articles[item_text] = item_href
print(articles)
1
  • Вы просто нашли все div, а надо было взять ссылки. Измените articles_title = soup.find_all('a', class_='link') 31 мая 2022 в 15:54

1 ответ 1

0
item_href =f'''https://lainelir2.pythonanywhere.com{item.a['href']}'''

Ваш ответ

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