Abderrahmen Euchi نشر 29 مارس أرسل تقرير نشر 29 مارس (معدل) جعلت 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() تم التعديل في 29 مارس بواسطة Abderrahmen Euchi 1 اقتباس
1 ياسر مسكين نشر 29 مارس أرسل تقرير نشر 29 مارس في حال كان سؤالك متعلقا بإحدى الدورات التي قمت بالاشتراك فيها، أرجو منك الانتقال إلى قسم "دوراتي" ثم أسفل الدرس الذي واجهت فيه المشكلة، قم بإضافة سؤالك هناك، وهذا لمساعدتك بشكل أفضل. أما إن لم يكن كذلك فأرجو توضيح سؤالك أكثر وفي أي سياق تريد أن يعمل هذا الكود. اقتباس
1 Mustafa Suleiman نشر 29 مارس أرسل تقرير نشر 29 مارس ستجد أسفل فيديو الدرس في نهاية الصفحة صندوق تعليقات كما هنا، أرجو طرح الأسئلة أسفل الدرس وليس هنا في قسم أسئلة البرمجة حيث نطرح الأسئلة العامة الغير متعلقة بمحتوى الدورة أو الدرس، وذلك لمساعدتك بشكل أفضل. 1 اقتباس
0 Mustafa Suleiman نشر 29 مارس أرسل تقرير نشر 29 مارس بتاريخ On 29/3/2025 at 18:31 قال Abderrahmen Euchi: هل يمكنني ان احذف السؤال؟ أظهر المزيد لا حاجة لحذفه، وليس هناك إمكانية للحذف، التعديل فقط. اقتباس
السؤال
Abderrahmen Euchi
جعلت 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()
تم التعديل في بواسطة Abderrahmen Euchi4 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.