Ruslan Sukhovii
New member
- 24.02.2023
 
- 2
 
- 0
 
Создаю дискорд бота на питоне что бы он парсил новости с сайта Dota2.com/news/, находил последние новости и публиковал их в дискорд мой, проблема в том что он не находит новость, почему? P.S. Я начинающий, вот пример кода, даже опеределенную новость не находит
	
	
	
	
		
В итоге вот что пишет в терминале
[2023-02-24 01:07:23] [INFO ] discord.client: logging in using static token
[2023-02-24 01:07:24] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 6836826eac4b2e16c831adcaff99ad28).
Dota 2 Новости/Обновление BOT#7442 connected to Discord!
Unable to find news
Unable to find news
				
			
		Python:
	
	import discord
import asyncio
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from bs4 import BeautifulSoup
TOKEN = ''
CHANNEL_ID = ''
# path to Edge driver
DRIVER_PATH = r'C:\Users\49152\Downloads\edgedriver_win64\msedgedriver.exe'
intents = discord.Intents.default()
intents.members = True  # Добавляем опцию members
client = discord.Client(intents=intents)
# Edge options
options = webdriver.EdgeOptions()
options.use_chromium = True
options.add_argument('--headless')  # запуск браузера в фоновом режиме
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')  # отключение использования GPU
# создаем сервис EdgeDriver
service = Service(DRIVER_PATH)
# создаем экземпляр драйвера Edge
driver = webdriver.Edge(service=service, options=options)
@client.event
async def on_ready():
    print(f'{client.user} connected to Discord!')
    while True:
        await send_news()
        # wait 5 minutes before the next iteration
        await asyncio.sleep(300)
async def send_news():
    url = 'Cheaters Will Never Be Welcome in Dota'
    driver.get(url)
    soup = BeautifulSoup(driver.page_source, 'html.parser')
    news_list = []
    newsentry_list = soup.find_all('div', class_='blogentrypage_BlogEntryPage_3PVZq')
    if not news_list:
        print('Unable to find news')
        return
    for news in news_list:
        title = news.h2.text.strip()
        description = news.p.text.strip()
        link = 'Dota 2' + news.a['href']
        channel = client.get_channel(CHANNEL_ID)
        await channel.send(f'**{title}**\n{description}\n{link}')
    print('News sent')
client.run(TOKEN)
	В итоге вот что пишет в терминале
[2023-02-24 01:07:23] [INFO ] discord.client: logging in using static token
[2023-02-24 01:07:24] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 6836826eac4b2e16c831adcaff99ad28).
Dota 2 Новости/Обновление BOT#7442 connected to Discord!
Unable to find news
Unable to find news
			
				Последнее редактирование: