Çözüldü Python Kodundaki Hata Nasıl Çözülür?

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

ardozcnn

Femtopat
Katılım
1 Şubat 2023
Mesajlar
6
Daha fazla  
Cinsiyet
Erkek
Python:
@client.command()
async def uçuş(ctx, city1: str, city2: str, date: str):
 city1 = city1.replace(" ", "+")
 city2 = city2.replace(" ", "+")
 url = f"https://www.kayak.com/flights/{city1}-{city2}/{date}?sort=bestflight_a"
 sayfa = requests.get(url)
 html_sayfa = BeautifulSoup(sayfa.content, "html.parser")
 flight = html_sayfa.find("div", class_="top").getText()
 if flight:
 flight = flight.getText()
 embed = discord.Embed(title = "UÇUŞ" , description = f"```{flight}```", color = discord.Colour.red())
 await ctx.send(embed=embed)
 else:
 await ctx.send("Hata var.")

Bu kod kayak.com sitesinden Discord'a yazılana göre şehre göre ve tarihe göre arama yapıyor. Ben buradan en ucuz uçuşu bulmaya çalışıyorum. Bir türlü.

Python:
flight = html_sayfa.find("div", class_="top").getText()

"Class_="nin nerede olduğunu bulamıyorum sitede ve en ucuz uçuşu bulamıyor.
 
Hocam, class isimleri ve Div'ler zaman icerisinde değişebiliyor. Site üzerinden uçuş isimlerinin olduğu güncel class ismini çekmeyi denediniz mi?
 
Bunu dener misin? Ucuz uçuşu bulacak şekilde düzenledim.

Python:
@client.command()
async def uçuş(ctx, city1: str, city2: str, date: str):
    city1 = city1.replace(" ", "+")
    city2 = city2.replace(" ", "+")
    url = f"https://www.kayak.com/flights/{city1}-{city2}/{date}?sort=price_a"
    sayfa = requests.get(url)
    html_sayfa = BeautifulSoup(sayfa.content, "html.parser")
    flight = html_sayfa.find("div", class_="top").getText()
    if flight:
        flight = flight.getText()
        embed = discord.Embed(title = "UÇUŞ" , description = f"```{flight}```", color = discord.Colour.red())
        await ctx.send(embed=embed)
    else:
        await ctx.send("Hata var.")
 
Son düzenleme:
Hocam, class isimleri ve Div'ler zaman icerisinde değişebiliyor. Site üzerinden uçuş isimlerinin olduğu güncel class ismini çekmeyi denediniz mi?

Hocam birkaç farklı site denedim hiçbirisi çalışmıyor.

Bunu dener misin? Ucuz uçuşu bulacak şekilde düzenledim.

Python:
@client.command()
async def uçuş(ctx, city1: str, city2: str, date: str):
 city1 = city1.replace(" ", "+")
 city2 = city2.replace(" ", "+")
 url = f"https://www.kayak.com/flights/{city1}-{city2}/{date}?sort=price_a"
 sayfa = requests.get(url)
 html_sayfa = BeautifulSoup(sayfa.content, "html.parser")
 flight = html_sayfa.find("div", class_="top").getText()
 if flight:
 flight = flight.getText()
 embed = discord.Embed(title = "UÇUŞ" , description = f"```{flight}```", color = discord.Colour.red())
 await ctx.send(embed=embed)
 else:
 await ctx.send("Hata var.")

Python:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'getText'

Hatası alıyorum.
 
Hocam birkaç farklı site denedim hiçbirisi çalışmıyor.



Python:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'getText'

Hatası alıyorum.
Python:
@client.command()
async def uçuş(ctx, city1: str, city2: str, date: str):
city1 = city1.replace(" ", "+")
city2 = city2.replace(" ", "+")
url = f"https://www.kayak.com/flights/{city1}-{city2}/{date}?sort=price_a"
sayfa = requests.get(url)
html_sayfa = BeautifulSoup(sayfa.content, "html.parser")
flight = html_sayfa.find("div", class_="top")
if flight:
flight = flight.getText()
embed = discord.Embed(title = "UÇUŞ" , description = f"{flight}", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
await ctx.send("Aradığınız uçuş bulunamadı.")

Bunu dener misin?
 
Son attığınız kod üzerinde biraz daha düzenleme yapınca çalıştı. Teşekkür ederim.

Python:
@client.command()
async def uçuş(ctx, city1: str, city2: str, date: str):
city1 = city1.replace(" ", "+")
city2 = city2.replace(" ", "+")
url = f"https://www.kayak.com/flights/{city1}-{city2}/{date}?sort=price_a"
sayfa = requests.get(url)
html_sayfa = BeautifulSoup(sayfa.content, "html.parser")
flight = html_sayfa.find("div", class_="top")
if flight:
flight = flight.getText()
embed = discord.Embed(title = "UÇUŞ" , description = f"{flight}", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
await ctx.send("Aradığınız uçuş bulunamadı.")

Bunu dener misin?
 

Yeni konular

Geri
Yukarı