@Vlad242

Пишу парсер. Как найти все ссылки и названия вопросов?

import requests
from bs4 import BeautifulSoup
def trade_spiders (max_page):
    page = 1
    while page <= max_page:
        url = 'https://www.toster.ru/questions' + str(page)
        source_code = requests.get(url)
        plain_text = source_code.content
        soup = BeautifulSoup(plain_text, 'html.parser')
        spider = soup.find('h2').text
        main_title = soup.find_all(('a', {"class": "question__title-link question__title-link_list"}))
        print(spider)
        print(main_title)
        page+=1

trade_spiders(1)


5c226f39c47e6160699014.png
  • Вопрос задан
  • 2104 просмотра
Решения вопроса 1
@Vlad242 Автор вопроса
import requests
from bs4 import BeautifulSoup
def trade_spiders (max_page):
    page = 1
    while page <= max_page:
        url = 'https://toster.ru/questions/latest?page=' + str(page)
        source_code = requests.get(url)
        soup = BeautifulSoup(source_code.text, 'html.parser')
        main_title = soup.find_all('a', {"class": "question__title-link"})
        for title in main_title:
            print(title.text.strip(), title.get('href')) # Первый элемент - название, второй - ссылка.
        page+=1

trade_spiders(1)
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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