جعلت deepseek يعطيني هذا الكود ، ما رآيكم؟
import requests
from bs4 import BeautifulSoup
def get_weather_data():
try:
url = 'https://world-weather.info/'
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
response = requests.get(url, headers=headers)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
# العثور على القسم الرئيسي
resorts_section = soup.find('div', id='resorts')
if not resorts_section:
raise ValueError("لم يتم العثور على قسم المدن")
weather_data = []
# استخراج البيانات من كل كتلة resorts-blocks
for block in resorts_section.find_all('div', class_='resorts-blocks'):
for city_div in block.find_all('div'):
# استخراج اسم المدينة
city_link = city_div.find('a')
if not city_link:
continue
city = city_link.text.strip()
country = city_link['href'].split('/')[-3].replace('_', ' ').title()
# استخراج درجة الحرارة وحالة الطقس
temp_span = city_div.find('span')
if temp_span:
temperature = temp_span.text.strip()
weather_icon = temp_span.find('span', class_='tooltip')
condition = weather_icon['title'] if weather_icon else "غير معروف"
else:
temperature = "N/A"
condition = "غير معروف"
weather_data.append({
'البلد': country,
'المدينة': city,
'درجة الحرارة': temperature,
'حالة الطقس': condition
})
# عرض النتائج
print(f"تم استخراج بيانات {len(weather_data)} مدينة:")
for i, item in enumerate(weather_data, 1):
print(f"{i}. {item['المدينة']}, {item['البلد']}:")
print(f" - درجة الحرارة: {item['درجة الحرارة']}")
print(f" - الحالة الجوية: {item['حالة الطقس']}")
print("-" * 40)
return weather_data
except Exception as e:
print(f"حدث خطأ: {e}")
return None
# تشغيل الدالة
get_weather_data()