اذهب إلى المحتوى

السؤال

Recommended Posts

  • 1
نشر

على فرض نريد استخراج جميع العناوين الموجودة ضمن الصفحة الرئيسية لأكاديمية حسوب، يمكننا القيام كما يلي:

from bs4 import BeautifulSoup
import requests
url = "https://academy.hsoub.com/" // نحدد عنوان الويب للصفحة الهدف
# المحدد url إلى عنوان GET إرسال طلب 
# للحصول على البيانات من الخادم
req = requests.get(url)
# BeautifulSoup الآن لتحليل المستند ، نقوم بتمريره إلى باني
# كذلك نحدد المحلل الذي نريد استخدامه
soup = BeautifulSoup(req.text, "html.parser") # هنا استخدمنا المحلل الافتراضي
print(soup.title) # هنا سنعرض عنوان الصفحة
# الخرج
# <title>أكاديمية حسوب</title>

حيث أن req.text تُرجع محتوى الاستجابة بترميز unicode. ولتحليل مستند ، نقوم بتمريره إلى باني BeautifulSoup. حيث يمكنك تمرير سلسلة كما فعلنا أو مقبض لملف مفتوح (سأعرض لك ذلك بعد قليل). ثم تقوم BeautifulSoup بتحليل المستند باستخدام أفضل محلل متاح، وهنا سيستخدم محلل HTML (وهو المحلل الافتراضي).
الآن لاستخراج جميع عناوين URL داخل صفحة ويب. نحتاج فقط إلى إضافة السطر أدناه من التعليمات البرمجية:

for link in soup.find_all('a'): # إيجاد كل العناوين
    print(link.get('href')) # استخراجها وطباعتها

الخرج:

#elContent
https://academy.hsoub.com/discover/
https://academy.hsoub.com/search/
#
https://academy.hsoub.com/
https://academy.hsoub.com/login/
https://academy.hsoub.com/login/?loginProcess=Hsoub&ref=aHR0cHM6Ly9hY2FkZW15Lmhzb3ViLmNvbS9sb2dpbi8=&csrf=06bb48a1b837697033df6270ca54b751
https://academy.hsoub.com/register/
#
https://academy.hsoub.com/index.php?app=core&module=search&controller=search&csrfKey=06bb48a1b837697033df6270ca54b751
https://academy.hsoub.com/search/
https://academy.hsoub.com
https://academy.hsoub.com/discover/
https://academy.hsoub.com/search/
#
http://twitter.com/HsoubAcademy
http://www.facebook.com/HsoubAcademy
https://www.youtube.com/channel/UCJv37tcBvJlBF2MoVMRMvbQ
https://academy.hsoub.com/programming/general/%D8%AA%D8%B9%D9%84%D9%85-%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-r662/
https://wiki.hsoub.com
#
https://academy.hsoub.com/#
https://academy.hsoub.com/entrepreneurship/
https://academy.hsoub.com/freelance/
https://academy.hsoub.com/marketing/
https://academy.hsoub.com/programming/
https://academy.hsoub.com/design/
https://academy.hsoub.com/devops/
https://academy.hsoub.com/apps/
https://academy.hsoub.com/certificates/
#
https://academy.hsoub.com/questions/
https://academy.hsoub.com/questions/c5-entrepreneurship/
https://academy.hsoub.com/questions/c8-freelance/
https://academy.hsoub.com/questions/c7-marketing/
https://academy.hsoub.com/questions/c3-programming/
https://academy.hsoub.com/questions/c4-design/
https://academy.hsoub.com/questions/c6-devops/
https://academy.hsoub.com/questions/c9-apps/
https://academy.hsoub.com/questions/c10-certificates/
#
https://academy.hsoub.com/files/
https://academy.hsoub.com/files/c2-entrepreneurship/
https://academy.hsoub.com/files/c3-freelance/
https://academy.hsoub.com/files/c4-marketing/
https://academy.hsoub.com/files/c5-programming/
https://academy.hsoub.com/files/c6-design/
https://academy.hsoub.com/files/c7-devops/
#
https://academy.hsoub.com/store/
https://academy.hsoub.com/store/c1-%D8%AF%D9%88%D8%B1%D8%A7%D8%AA-%D8%AA%D8%B9%D9%84%D9%8A%D9%85%D9%8A%D8%A9/
#
https://academy.hsoub.com/store/gift-cards/
https://academy.hsoub.com/store/redeem/
#
#
#
https://academy.hsoub.com/discover/
https://academy.hsoub.com/
None
https://academy.hsoub.com/learn/computer-science/
https://academy.hsoub.com/learn/front-end-web-development/
https://academy.hsoub.com/learn/javascript-application-development/
https://academy.hsoub.com/learn/php-web-application-development/
https://academy.hsoub.com/learn/hybrid-mobile-application-development/
https://academy.hsoub.com/learn/ruby-web-application-development/
https://academy.hsoub.com/entrepreneurship/
https://academy.hsoub.com/freelance/
https://academy.hsoub.com/marketing/
https://academy.hsoub.com/programming/
https://academy.hsoub.com/design/
https://academy.hsoub.com/devops/
https://academy.hsoub.com/apps/
https://academy.hsoub.com/certificates/
#elTabBar
None
None
None
None
None
None
None
None
https://academy.hsoub.com/questions/4-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%84%D8%A3%D9%81%D9%83%D8%A7%D8%B1-%D8%BA%D9%8A%D8%B1-%D8%A7%D9%84%D8%AA%D9%82%D9%84%D9%8A%D8%AF%D9%8A%D8%A9-%D9%84%D8%A5%D9%86%D8%B4%D8%A7%D8%A1-%D9%85%D8%B4%D8%B1%D9%88%D8%B9-%D9%86%D8%A7%D8%AC%D8%AD%D8%9F/
https://academy.hsoub.com/questions/5551-%D9%87%D9%84-%D9%8A%D9%8F%D9%85%D9%83%D9%86-%D8%A3%D9%86-%D8%AA%D9%88%D8%A7%D8%AC%D9%87-%D8%B4%D8%B1%D9%83%D8%AA%D9%8A-%D8%A7%D9%84%D9%86%D8%A7%D8%B4%D8%A6%D8%A9-%D8%A7%D9%84%D9%85%D9%8F%D9%86%D8%A7%D9%81%D8%B3%D9%8A%D9%86-%D8%A8%D8%AC%D8%AF%D8%A7%D8%B1%D8%A9%D8%9F/
https://academy.hsoub.com/questions/6155-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A3%D8%B1%D9%83%D8%A7%D9%86-%D8%AE%D8%B7%D8%A9-%D8%A7%D9%84%D8%B9%D9%85%D9%84-%D8%A7%D9%84%D8%AC%D9%8A%D8%AF%D8%A9%D8%9F/
https://academy.hsoub.com/questions/6158-%D9%83%D9%8A%D9%81-%D8%A3%D8%AD%D8%B5%D9%84-%D8%B9%D9%84%D9%89-%D8%AA%D9%85%D9%88%D9%8A%D9%84-%D8%B0%D8%A7%D8%AA%D9%8A-%D9%84%D9%85%D8%B4%D8%B1%D9%88%D8%B9%D9%8A%D8%9F/
https://academy.hsoub.com/questions/35-%D9%87%D9%84-%D9%8A%D9%85%D9%83%D9%86-%D9%84%D8%B4%D8%B1%D9%83%D8%A9-%D9%86%D8%A7%D8%B4%D8%A6%D8%A9-%D8%A7%D9%86-%D8%AA%D8%B9%D8%AA%D9%85%D8%AF-%D8%B9%D9%84%D9%89-%D8%AE%D9%85%D8%B3%D8%A7%D8%AA-%D8%A3%D9%88-%D9%81%D8%A7%D9%8A%D9%81%D8%B1-%D9%84%D8%AE%D8%AF%D9%85%D8%A7%D8%AA-%D8%AA%D8%AD%D8%AA%D8%A7%D8%AC%D9%87%D8%A7%D8%9F/
https://academy.hsoub.com/questions/790-%D9%83%D9%8A%D9%81-%D8%A3%D9%82%D9%86%D8%B9-%D8%A7%D9%84%D9%85%D8%B3%D9%88%D9%82%D9%8A%D9%86-%D8%A8%D8%AA%D8%B3%D9%88%D9%8A%D9%82-%D9%85%D9%86%D8%AA%D8%AC%D9%8A%D8%9F/
https://academy.hsoub.com/questions/284-%D9%83%D9%8A%D9%81-%D8%A3%D9%82%D9%88%D9%85-%D8%A8%D8%AA%D8%AD%D9%81%D9%8A%D8%B2-%D9%88%D8%AA%D8%B7%D9%88%D9%8A%D8%B1-%D9%81%D8%B1%D9%8A%D9%82-%D8%B9%D9%85%D9%84%D9%8A-%D9%81%D9%8A-%D8%B3%D8%A8%D9%8A%D9%84-%D8%A7%D9%84%D8%AD%D8%B5%D9%88%D9%84-%D8%B9%D9%84%D9%89-%D8%A3%D9%81%D8%B6%D9%84-%D8%A7%D9%84%D9%86%D8%AA%D8%A7%D8%A6%D8%AC%D8%9F/
https://academy.hsoub.com/questions/295-%D9%87%D9%84-%D9%8A%D8%AC%D8%A8-%D8%B9%D9%84%D9%8A-%D8%A7%D9%84%D9%82%D9%84%D9%82-%D8%A8%D8%B4%D8%A3%D9%86-%D8%A7%D9%84%D8%B9%D9%84%D8%A7%D9%85%D8%A9-%D8%A7%D9%84%D8%AA%D8%AC%D8%A7%D8%B1%D9%8A%D8%A9-%D8%A7%D9%84%D8%A7%D8%B3%D9%85%D8%A7%D9%84%D8%B4%D8%B9%D8%A7%D8%B1-%D9%82%D8%A8%D9%84-%D8%A5%D8%B7%D9%84%D8%A7%D9%82-%D9%85%D8%B4%D8%B1%D9%88%D8%B9%D9%8A-%D8%A7%D9%84%D8%AC%D8%AF%D9%8A%D8%AF%D8%9F/
https://academy.hsoub.com/questions/17-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A3%D9%81%D8%B6%D9%84-%D8%B7%D8%B1%D9%8A%D9%82%D8%A9-%D9%84%D9%84%D8%AA%D9%91%D8%B9%D8%A7%D9%85%D9%84-%D9%85%D8%B9-%D8%B7%D9%84%D8%A8%D8%A7%D8%AA-%D8%A7%D9%84%D8%AA%D8%B9%D8%AF%D9%8A%D9%84-%D8%A7%D9%84%D9%85%D9%8F%D8%AA%D9%83%D8%B1%D9%91%D8%B1%D8%A9-%D9%85%D9%86-%D8%A7%D9%84%D8%B9%D9%85%D9%8A%D9%84%D8%9F/
https://academy.hsoub.com/questions/33-%D8%A3%D9%8A%D9%87%D8%A7-%D8%A3%D9%81%D8%B6%D9%84-%D9%84%D9%84%D8%AD%D8%B5%D9%88%D9%84-%D8%B9%D9%84%D9%89-%D8%AE%D8%AF%D9%85%D8%A7%D8%AA-%D8%B9%D8%A7%D9%84%D9%8A%D8%A9-%D8%A7%D9%84%D8%AC%D9%88%D8%AF%D8%A9-%D9%85%D9%8F%D8%B3%D8%AA%D9%82%D9%84-%D8%A3%D9%85-%D8%AE%D9%85%D8%B3%D8%A7%D8%AA-%D8%A3%D9%85-%D9%85%D9%88%D8%A7%D9%82%D8%B9-%D8%A3%D8%AE%D8%B1%D9%89%D8%9F/
https://academy.hsoub.com/questions/3330-%D9%83%D9%8A%D9%81-%D8%A3%D9%88%D8%A7%D8%B2%D9%86-%D8%A8%D9%8A%D9%86-%D8%AF%D8%B1%D8%A7%D8%B3%D8%AA%D9%8A-%D9%88%D8%A7%D9%84%D8%B9%D9%85%D9%84-%D8%A7%D9%84%D8%AD%D8%B1%D8%9F/
https://academy.hsoub.com/questions/19-%D9%83%D9%8A%D9%81-%D8%B3%D8%AA%D8%AA%D8%B9%D8%A7%D9%85%D9%84-%D9%85%D8%B9-%D8%B9%D9%85%D9%8A%D9%84-%D9%84%D8%A7-%D9%8A%D8%B1%D9%8A%D8%AF-%D8%A7%D9%84%D8%AF%D9%81%D8%B9%D8%9F/
https://academy.hsoub.com/questions/278-%D9%87%D9%84-%D9%8A%D8%AC%D8%A8-%D8%A3%D9%86-%D8%A3%D8%AA%D8%B1%D9%83-%D9%88%D8%B8%D9%8A%D9%81%D8%AA%D9%8A-%D8%A7%D9%84%D8%AD%D8%A7%D9%84%D9%8A%D8%A9-%D9%84%D9%84%D8%B9%D9%85%D9%84-%D9%83%D9%85%D8%B3%D8%AA%D9%82%D9%84%D8%9F/
https://academy.hsoub.com/questions/32-%D9%83%D9%8A%D9%81-%D8%A3%D8%AD%D8%B5%D9%84-%D8%B9%D9%84%D9%89-%D8%A3%D9%88%D9%84-%D9%88%D8%B8%D9%8A%D9%81%D8%A9-%D9%84%D9%8A-%D9%83%D9%85%D8%B3%D8%AA%D9%82%D9%84%D8%9F/
https://academy.hsoub.com/questions/50-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A3%D9%87%D9%85-%D9%85%D9%88%D8%A7%D9%82%D8%B9-%D8%A7%D9%84%D8%B9%D9%85%D9%84-%D8%A7%D9%84%D8%AD%D8%B1%D8%9F/
https://academy.hsoub.com/questions/316-%D9%85%D9%86-%D8%A3%D9%8A%D9%86-%D8%A3%D8%AD%D8%B5%D9%84-%D8%B9%D9%84%D9%89-%D8%A7%D9%84%D8%AE%D8%A8%D8%B1%D8%A9-%D8%A5%D8%B0%D8%A7-%D9%83%D8%A7%D9%86%D8%AA-%D8%A7%D9%84%D8%AC%D9%85%D9%8A%D8%B9-%D9%8A%D8%B7%D9%84%D8%A8%D9%87%D8%A7-%D8%B9%D9%86%D8%AF-%D8%A7%D9%84%D8%AA%D9%88%D8%B8%D9%8A%D9%81%D8%9F/
https://academy.hsoub.com/questions/15-%D9%87%D9%84-%D9%85%D9%86-%D9%86%D8%B5%D8%A7%D8%A6%D8%AD-%D9%84%D8%A2%D9%84%D9%8A%D8%A9-%D9%85%D9%86%D8%A7%D8%B3%D8%A8%D8%A9-%D9%88%D9%81%D8%B9%D8%A7%D9%84%D8%A9-%D9%84%D8%B5%D8%B1%D9%81-%D9%85%D9%8A%D8%B2%D8%A7%D9%86%D9%8A%D8%A9-%D8%A7%D9%84%D8%AF%D8%B9%D8%A7%D9%8A%D8%A9%D8%9F/
https://academy.hsoub.com/questions/7046-%D9%83%D9%8A%D9%81-%D8%A3%D8%B2%D9%8A%D8%AF%D9%8F-%D9%85%D9%86-%D8%A3%D8%B1%D8%A8%D8%A7%D8%AD-%D8%A7%D9%84%D8%A5%D8%B9%D9%84%D8%A7%D9%86%D8%A7%D8%AA%D8%9F/
https://academy.hsoub.com/questions/54-%D8%A3%D9%8A%D9%87%D9%85%D8%A7-%D8%A3%D9%81%D8%B6%D9%84-%D9%84%D9%84%D9%86%D8%B4%D8%B1-%D8%B9%D9%84%D9%89-%D8%A7%D9%84%D8%B4%D8%A8%D9%83%D8%A7%D8%AA-%D8%A7%D9%84%D8%A7%D8%AC%D8%AA%D9%85%D8%A7%D8%B9%D9%8A%D8%A9-buffer-%D8%A3%D9%85-hootsuite%D8%9F/
https://academy.hsoub.com/questions/461-%D9%83%D9%8A%D9%81-%D8%A3%D9%82%D9%88%D9%85-%D8%A8%D8%AA%D8%B3%D8%B9%D9%8A%D8%B1-%D9%85%D9%86%D8%AA%D8%AC%D8%A7%D8%AA%D9%8A%D8%9F/
https://academy.hsoub.com/questions/2046-%D9%83%D9%8A%D9%81-%D8%A3%D8%B3%D8%AA%D8%AE%D8%AF%D9%85-%D9%85%D9%88%D8%A7%D9%82%D8%B9-%D8%A7%D9%84%D8%AA%D9%88%D8%A7%D8%B5%D9%84-%D8%A7%D9%84%D8%A7%D8%AC%D8%AA%D9%85%D8%A7%D8%B9%D9%8A-%D9%84%D8%AA%D9%82%D8%AF%D9%8A%D9%85-%D8%AE%D8%AF%D9%85%D8%A9-%D8%B9%D9%85%D9%84%D8%A7%D8%A1-%D9%85%D9%8F%D9%85%D9%8A%D8%B2%D8%A9%D8%9F/
https://academy.hsoub.com/questions/2893-%D9%83%D9%8A%D9%81-%D8%A3%D8%B1%D8%A8%D8%AD-%D9%85%D9%86-%D8%A7%D9%84%D8%AA%D8%B3%D9%88%D9%8A%D9%82-%D8%A8%D8%A7%D9%84%D8%B9%D9%85%D9%88%D9%84%D8%A9%D8%9F/
https://academy.hsoub.com/questions/2839-%D9%85%D8%A7%D9%87%D9%8A-%D8%A7%D9%84%D8%B7%D8%B1%D9%82-%D8%A7%D9%84%D9%85%D9%85%D9%86%D9%88%D8%B9%D8%A9-%D9%88%D8%A7%D9%84%D9%85%D8%AD%D8%B8%D9%88%D8%B1%D8%A9-%D9%81%D9%8A-%D8%A7%D9%84%D8%AA%D8%B3%D9%88%D9%8A%D9%82-%D8%A8%D8%A7%D9%84%D8%B9%D9%85%D9%88%D9%84%D8%A9%D8%9F/
https://academy.hsoub.com/questions/626-%D9%83%D9%8A%D9%81-%D8%A3%D9%83%D8%AA%D8%A8-%D8%B1%D8%B3%D8%A7%D9%84%D8%A9-%D8%AA%D8%B3%D9%88%D9%8A%D9%82%D9%8A%D8%A9-%D9%85%D8%A4%D8%AB%D8%B1%D8%A9%D8%9F/
https://academy.hsoub.com/questions/11-%D9%83%D9%8A%D9%81-%D9%8A%D9%85%D9%83%D9%86-%D8%AA%D8%B9%D9%84%D9%85-%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-%D9%84%D8%BA%D9%8A%D8%B1-%D8%A7%D9%84%D9%85%D8%A8%D8%B1%D9%85%D8%AC%D9%8A%D9%86-%D8%9F/
https://academy.hsoub.com/questions/267-%D9%85%D8%A7-%D9%87%D9%8A-%D9%84%D8%BA%D8%A9-%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-%D8%A7%D9%84%D8%A3%D9%81%D8%B6%D9%84-%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-%D9%85%D9%88%D8%A7%D9%82%D8%B9-%D8%A7%D9%84%D8%A5%D9%86%D8%AA%D8%B1%D9%86%D8%AA%D8%9F/
https://academy.hsoub.com/questions/288-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%84%D8%B7%D8%B1%D9%82-%D8%A7%D9%84%D9%85%D9%8F%D8%B3%D8%AA%D8%AE%D8%AF%D9%85%D8%A9-%D9%81%D9%8A-%D8%AA%D8%B3%D8%B1%D9%8A%D8%B9-%D8%AA%D8%AD%D9%85%D9%8A%D9%84-%D8%A7%D9%84%D9%85%D9%88%D8%A7%D9%82%D8%B9%D8%9F/
https://academy.hsoub.com/questions/364-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%84%D9%85%D8%AF%D8%A9-%D8%A7%D9%84%D9%84%D8%A7%D8%B2%D9%85%D8%A9-%D9%84%D8%AA%D8%B9%D9%84%D9%85-%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9%D8%9F/
https://academy.hsoub.com/questions/1193-%D9%85%D8%A7-%D9%87%D9%8A-%D9%84%D8%BA%D8%A7%D8%AA-%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-%D8%A7%D9%84%D9%85%D8%B3%D8%AA%D8%AE%D8%AF%D9%85%D8%A9-%D9%81%D9%8A-%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-%D8%A5%D8%B6%D8%A7%D9%81%D8%A7%D8%AA-%D9%84%D9%85%D8%AA%D8%B5%D9%81%D8%AD%D8%A7%D8%AA-%D8%A7%D9%84%D8%A5%D9%86%D8%AA%D8%B1%D9%86%D8%AA%D8%9F/
https://academy.hsoub.com/questions/268-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%84%D8%A3%D8%AF%D9%88%D8%A7%D8%AA-%D9%88%D8%A7%D9%84%D9%85%D8%AA%D8%B7%D9%84%D8%A8%D8%A7%D8%AA-%D8%A7%D9%84%D9%84%D8%A7%D8%B2%D9%85%D8%A9-%D9%84%D8%AA%D8%B9%D8%B1%D9%8A%D8%A8-%D9%82%D8%A7%D9%84%D8%A8-wordpress%D8%9F/
https://academy.hsoub.com/questions/524-%D9%83%D9%8A%D9%81-%D8%A3%D8%BA%D9%8A%D9%91%D8%B1-%D8%A7%D8%B3%D9%85-%D8%AD%D9%82%D9%84-%D9%81%D9%8A-%D9%82%D8%A7%D8%B9%D8%AF%D8%A9-%D8%A8%D9%8A%D8%A7%D9%86%D8%A7%D8%AA-mysql%D8%9F/
https://academy.hsoub.com/questions/269-%D9%85%D8%A7-%D9%87%D9%88-%D8%A3%D9%81%D8%B6%D9%84-%D9%83%D8%AA%D8%A7%D8%A8-%D9%8A%D8%AC%D8%A8-%D9%82%D8%B1%D8%A7%D8%A1%D8%AA%D9%87-%D9%84%D8%AA%D8%B9%D9%84%D9%85-%D9%84%D8%BA%D8%A9-%D8%AC%D8%A7%D9%81%D8%A7-%D8%B3%D9%83%D8%B1%D8%A8%D8%AA-javascript%D8%9F/
https://academy.hsoub.com/questions/8235-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%84%D8%A8%D8%B1%D8%A7%D9%85%D8%AC-%D8%A7%D9%84%D8%AA%D9%8A-%D9%8A%D8%AC%D8%A8-%D8%AA%D8%B9%D9%84%D9%85%D9%87%D8%A7-%D9%84%D8%A5%D9%86%D8%B4%D8%A7%D8%A1-%D9%81%D9%8A%D9%84%D9%85-%D8%B1%D8%B3%D9%88%D9%85-%D9%85%D8%AA%D8%AD%D8%B1%D9%83%D8%A9-3d-%D9%85%D8%AB%D9%84-%D9%81%D9%8A%D9%84%D9%85-ice-age%D8%9F/
https://academy.hsoub.com/questions/8034-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%84%D8%A3%D8%A8%D8%B9%D8%A7%D8%AF-%D8%A7%D9%84%D9%85%D8%AB%D8%A7%D9%84%D9%8A%D8%A9-%D9%84%D8%AA%D8%B5%D9%85%D9%8A%D9%85%D8%A7%D8%AA-%D8%A7%D9%84%D9%83%D8%B1%D9%88%D8%AA-%D9%88%D8%A7%D9%84%D8%A8%D9%88%D8%B3%D8%AA%D8%B1%D8%A7%D8%AA%D8%9F/
https://academy.hsoub.com/questions/8033-%D9%83%D9%8A%D9%81-%D9%84%D9%8A-%D8%A3%D9%86-%D8%A7%D8%AE%D8%AA%D8%A8%D8%B1-%D9%86%D9%81%D8%B3%D9%8A-%D9%81%D9%8A-%D8%A7%D9%84%D8%AA%D8%B5%D9%85%D9%8A%D9%85-%D9%83%D9%85%D8%A8%D8%AA%D8%AF%D8%A6%D8%9F/
https://academy.hsoub.com/questions/7871-%D9%85%D8%A7-%D9%87%D9%8A-%D9%85%D8%B9%D8%A7%D9%8A%D9%8A%D8%B1-%D8%AA%D8%AD%D8%AF%D9%8A%D8%AF-%D8%A7%D9%84%D8%B3%D8%B9%D8%B1-%D9%81%D9%8A-%D8%A7%D9%84%D8%AA%D8%B5%D9%85%D9%8A%D9%85%D8%9F/
https://academy.hsoub.com/questions/7608-%D9%85%D8%A7-%D9%87%D9%88-%D8%A7%D9%84%D8%A7%D9%86%D9%81%D9%88%D8%AC%D8%B1%D8%A7%D9%81%D9%8A%D9%83-%D9%88%D9%85%D8%A7-%D8%A3%D9%81%D8%B6%D9%84-%D8%A7%D9%84%D8%A8%D8%B1%D8%A7%D9%85%D8%AC-%D9%84%D8%A5%D9%86%D8%B4%D8%A7%D8%A1-%D8%AA%D8%B5%D8%A7%D9%85%D9%8A%D9%85%D9%87%D8%9F/
https://academy.hsoub.com/questions/7377-%D9%84%D9%85%D8%A7%D8%B0%D8%A7-%D8%AA%D8%B8%D9%87%D8%B1-%D8%A7%D9%84%D8%B5%D9%88%D8%B1%D8%A9-%D9%85%D8%A8%D9%83%D8%B3%D9%84%D8%A9-%D9%81%D9%8A-%D8%A7%D9%84%D9%84%D8%A7%D8%B3%D8%AA%D8%B1%D9%8A%D8%AA%D9%88%D8%B1%D8%9F/
https://academy.hsoub.com/questions/7349-%D9%87%D9%84-%D9%85%D9%86-%D8%A7%D9%84%D8%B6%D8%B1%D9%88%D8%B1%D9%8A-%D8%A7%D8%AA%D9%82%D8%A7%D9%86-%D9%85%D9%87%D8%A7%D8%B1%D8%A9-%D8%A7%D9%84%D8%B1%D8%B3%D9%85-%D8%A8%D8%A7%D9%84%D9%86%D8%B3%D8%A8%D8%A9-%D9%84%D9%84%D9%85%D8%B5%D9%85%D9%85%D8%9F/
https://academy.hsoub.com/questions/7157-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%84%D8%A8%D8%AF%D8%A7%D8%A6%D9%84-%D8%A7%D9%84%D9%85%D8%AC%D8%A7%D9%86%D9%8A%D8%A9-%D9%84%D9%84%D9%81%D9%88%D8%AA%D9%88%D8%B4%D9%88%D8%A8%D8%9F/
https://academy.hsoub.com/questions/8229-%D9%87%D9%84-%D9%85%D9%86-%D8%A7%D9%84%D8%A3%D9%81%D8%B6%D9%84-%D9%84%D9%8A-%D8%A7%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85-docker-%D9%83%D9%85%D8%B7%D9%88%D8%B1-php-%D8%A3%D9%85-%D8%A7%D9%84%D8%A5%D9%83%D8%AA%D9%81%D8%A7%D8%A1-%D8%A8%D8%A7%D9%84%D9%80-virtualbox%D8%9F/
https://academy.hsoub.com/questions/8186-%D9%87%D9%84-%D9%8A%D9%81%D8%B6%D9%84-%D8%A5%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85-nodejs-%D8%A8%D8%AF%D9%84%D8%A7%D9%8B-%D9%85%D9%86-nginx-%D9%88-apache%D8%9F/
https://academy.hsoub.com/questions/7365-%D9%85%D8%A7-%D9%87%D9%88-%D8%A3%D9%81%D8%B6%D9%84-%D9%86%D8%B8%D8%A7%D9%85-%D9%84%D9%8A%D9%86%D9%83%D8%B3-%D9%84%D9%84%D8%B3%D9%8A%D8%B1%D9%81%D8%B1%D8%A7%D8%AA%D8%9F/
https://academy.hsoub.com/questions/7131-%D9%87%D9%84-%D8%A7%D9%84%D8%A3%D9%81%D8%B6%D9%84-%D8%A7%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85-cpanel-%D8%A3%D9%85-%D8%AA%D8%AB%D8%A8%D9%8A%D8%AA-apache-php-mysql-%D9%8A%D8%AF%D9%88%D9%8A%D8%A7/
https://academy.hsoub.com/questions/7123-%D9%85%D8%A7%D9%87%D9%8A-%D8%A7%D9%84%D9%85%D9%87%D8%A7%D8%B1%D8%A7%D8%AA-%D8%A7%D9%84%D9%85%D8%B7%D9%84%D9%88%D8%A8%D8%A9-%D9%84%D9%84%D8%AA%D8%B9%D8%A7%D9%85%D9%84-%D9%85%D8%B9-%D8%AE%D8%A7%D8%AF%D9%85-vps%D8%9F/
https://academy.hsoub.com/questions/7077-%D9%83%D9%8A%D9%81-%D8%A3%D8%AE%D8%AA%D8%A7%D8%B1-%D8%B4%D8%B1%D9%83%D8%A9-%D8%A7%D8%B3%D8%AA%D8%B6%D8%A7%D9%81%D8%A9-%D9%85%D9%86%D8%A7%D8%B3%D8%A8%D8%A9%D8%9F/
https://academy.hsoub.com/questions/6998-%D9%83%D9%8A%D9%81-%D8%A3%D8%B6%D8%B9-%D8%AD%D8%AF%D9%88%D8%AF-%D9%84%D8%B3%D8%B1%D8%B9%D8%A9-%D8%A7%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85-%D8%A7%D9%84%D8%A5%D9%86%D8%AA%D8%B1%D9%86%D8%AA-%D8%B9%D9%84%D9%89-%D8%B3%D9%8A%D8%B1%D9%81%D8%B1-%D8%A3%D9%88%D8%A8%D9%88%D9%86%D8%AA%D9%88%D8%9F/
https://academy.hsoub.com/questions/6721-%D9%83%D9%8A%D9%81-%D8%A3%D8%B9%D9%85%D9%84-%D9%86%D8%B3%D8%AE%D8%A9-%D8%A7%D8%AD%D8%AA%D9%8A%D8%A7%D8%B7%D9%8A%D8%A9-%D9%85%D9%86-%D8%AE%D8%A7%D8%AF%D9%88%D9%85-vps-%D9%8A%D8%B9%D9%85%D9%84-%D8%A8%D9%86%D8%B8%D8%A7%D9%85-%D8%AF%D9%8A%D8%A8%D9%8A%D8%A7%D9%86%D8%9F/
https://academy.hsoub.com/questions/7243-%D9%85%D8%A7-%D9%81%D8%A7%D8%A6%D8%AF%D8%A9-%D8%B1%D8%AE%D8%B5-%D8%A7%D9%84%D8%A8%D8%B1%D8%A7%D9%85%D8%AC%D8%9F/
https://academy.hsoub.com/questions/7169-%D9%83%D9%8A%D9%81-%D8%A3%D8%B4%D9%81%D9%91%D8%B1-%D8%B3%D9%8A%D8%AF%D9%8A-%D8%A8%D8%AD%D9%8A%D8%AB-%D8%A3%D9%85%D9%86%D8%B9-%D8%B9%D9%85%D9%84%D9%8A%D8%A9-%D8%A7%D9%84%D9%86%D8%B3%D8%AE-%D9%85%D9%86%D9%87%D8%9F/
https://academy.hsoub.com/questions/6735-%D9%87%D9%84-%D9%8A%D9%85%D9%83%D9%86-%D8%AA%D8%BA%D9%8A%D9%8A%D8%B1-%D9%83%D9%84%D9%85%D8%A9-%D9%85%D8%B1%D9%88%D8%B1-%D9%88%D9%8A%D9%86%D8%AF%D9%88%D8%B2-%D8%AF%D9%88%D9%86-%D9%85%D8%B9%D8%B1%D9%81%D8%A9-%D8%A7%D9%84%D9%82%D8%AF%D9%8A%D9%85%D8%A9-%D8%A3%D9%88-%D9%81%D8%B1%D9%85%D8%AA%D8%A9-%D8%A7%D9%84%D8%AD%D8%A7%D8%B3%D9%88%D8%A8%D8%9F/
https://academy.hsoub.com/questions/145-%D9%83%D9%8A%D9%81-%D9%8A%D9%85%D9%83%D9%86%D9%86%D9%8A-%D8%AA%D9%86%D8%B2%D9%8A%D9%84-%D9%85%D9%88%D9%82%D8%B9-%D9%88%D9%8A%D8%A8-%D8%A8%D8%A7%D9%84%D9%83%D8%A7%D9%85%D9%84-%D9%85%D9%86-%D8%B3%D8%B7%D8%B1-%D8%A7%D9%84%D8%A3%D9%88%D8%A7%D9%85%D8%B1%D8%9F/
https://academy.hsoub.com/questions/4058-%D9%87%D9%84-%D9%8A%D8%AA%D9%88%D9%81%D8%B1-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D8%AC-%D9%84%D8%AA%D8%B9%D9%84%D9%8A%D9%85-%D8%A7%D9%84%D8%B7%D8%A8%D8%A7%D8%B9%D8%A9-%D8%A8%D8%A7%D9%84%D9%84%D9%85%D8%B3%D8%9F/
https://academy.hsoub.com/questions/3308-%D9%83%D9%8A%D9%81-%D8%A3%D8%B3%D8%AC%D9%91%D9%84-%D9%81%D9%8A%D8%AF%D9%8A%D9%88-%D9%84%D8%B3%D8%B7%D8%AD-%D8%A7%D9%84%D9%85%D9%83%D8%AA%D8%A8-%D9%81%D9%8A-%D9%84%D9%8A%D9%86%D9%83%D8%B3%D8%9F/
https://academy.hsoub.com/questions/4353-%D9%85%D8%A7-%D9%87%D9%8A-%D8%A3%D9%81%D8%B6%D9%84-%D8%A8%D8%B1%D8%A7%D9%85%D8%AC-%D8%A7%D9%84%D9%82%D8%B1%D8%A7%D8%A1%D8%A9-%D8%A7%D9%84%D9%84%D9%8A%D9%84%D9%8A%D8%A9-%D8%A7%D9%84%D9%85%D8%AA%D9%88%D9%81%D8%B1%D8%A9-%D8%B9%D9%84%D9%89-%D8%A3%D9%86%D8%AF%D8%B1%D9%88%D9%8A%D8%AF%D8%9F/
https://academy.hsoub.com/questions/4866-%D9%83%D9%8A%D9%81-%D8%A3%D8%AD%D8%B0%D9%81-%D8%A7%D9%84%D8%AA%D8%B7%D8%A8%D9%8A%D9%82%D8%A7%D8%AA-%D9%85%D9%86-%D8%AF%D8%A7%D8%AE%D9%84-%D9%86%D8%B8%D8%A7%D9%85-%D8%A7%D9%84%D8%AA%D8%B4%D8%BA%D9%8A%D9%84-%D9%88%D9%8A%D9%86%D8%AF%D9%88%D8%B2-10%D8%9F/
https://academy.hsoub.com/questions/4864-%D9%87%D9%84-%D9%87%D9%86%D8%A7%D9%84%D9%83-%D8%B4%D9%87%D8%A7%D8%AF%D8%A7%D8%AA-%D9%81%D9%8A-%D9%85%D8%AC%D8%A7%D9%84-%D8%A7%D9%84%D8%AA%D8%AD%D9%82%D9%8A%D9%82-%D8%A7%D9%84%D8%AC%D9%86%D8%A7%D8%A6%D9%8A-%D8%A7%D9%84%D8%A5%D9%84%D9%83%D8%AA%D8%B1%D9%88%D9%86%D9%8A%D8%9F/
https://academy.hsoub.com/questions/4794-%D9%85%D8%A7-%D9%87%D9%8A-%D8%B4%D9%87%D8%A7%D8%AF%D8%A9-ceh%D8%9F/
https://academy.hsoub.com/questions/5835-%D9%85%D8%A7%D9%87%D9%8A-%D8%A7%D9%84%D8%B4%D9%87%D8%A7%D8%AF%D8%A7%D8%AA-%D8%A7%D9%84%D9%85%D8%B7%D9%84%D9%88%D8%A8%D8%A9-%D9%81%D9%8A-%D9%85%D8%AC%D8%A7%D9%84-%D8%A7%D9%84%D8%B4%D8%A8%D9%83%D8%A7%D8%AA%D8%9F/
https://academy.hsoub.com/questions/4839-%D9%85%D8%A7-%D9%87%D9%8A-%D8%B4%D9%87%D8%A7%D8%AF%D8%A9-oscp%D8%9F/
https://academy.hsoub.com/questions/6400-%D9%87%D9%84-%D9%87%D9%86%D8%A7%D9%83-%D8%A7%D8%AE%D8%AA%D8%A8%D8%A7%D8%B1%D8%A7%D8%AA-%D9%88%D8%B4%D9%87%D8%A7%D8%AF%D8%A7%D8%AA-seo%D8%9F/
https://academy.hsoub.com/questions/3089-%D9%85%D8%A7%D8%B0%D8%A7-%D9%8A%D9%82%D8%B5%D8%AF-%D8%A8%D9%80-mcpd%D8%9F/
https://academy.hsoub.com/questions/6674-%D9%87%D9%84-%D9%8A%D8%AC%D8%A8-%D8%A5%D8%B9%D8%A7%D8%AF%D8%A9-%D8%A7%D9%84%D8%A7%D9%85%D8%AA%D8%AD%D8%A7%D9%86-%D9%83%D8%A7%D9%85%D9%84%D9%8B%D8%A7-%D9%85%D9%86-%D9%82%D8%A8%D9%84-%D8%AD%D8%A7%D9%85%D9%84%D9%8A-%D8%B4%D9%87%D8%A7%D8%AF%D8%A7%D8%AA-ccna-%D8%A7%D9%84%D9%82%D8%AF%D9%8A%D9%85%D8%A9%D8%9F/
https://academy.hsoub.com/questions/5140-%D9%87%D9%84-%D9%85%D9%86-%D9%86%D8%B5%D8%A7%D8%A6%D8%AD-%D9%84%D8%A7%D8%AE%D8%AA%D8%A8%D8%A7%D8%B1-rhcsa%D8%9F/
https://academy.hsoub.com/files/19-%D9%85%D8%AF%D8%AE%D9%84-%D8%A5%D9%84%D9%89-%D8%A7%D9%84%D8%AA%D8%B3%D9%88%D9%8A%D9%82/
https://academy.hsoub.com/files/18-%D8%A7%D9%84%D8%AF%D9%84%D9%8A%D9%84-%D8%A7%D9%84%D8%B9%D9%85%D9%84%D9%8A-%D8%A5%D9%84%D9%89-%D9%82%D9%88%D8%A7%D8%B9%D8%AF-%D8%A8%D9%8A%D8%A7%D9%86%D8%A7%D8%AA-postgresql/
https://academy.hsoub.com/files/17-%d9%85%d8%af%d8%ae%d9%84-%d8%a5%d9%84%d9%89-%d8%a7%d9%84%d8%b0%d9%83%d8%a7%d8%a1-%d8%a7%d9%84%d8%a7%d8%b5%d8%b7%d9%86%d8%a7%d8%b9%d9%8a-%d9%88%d8%aa%d8%b9%d9%84%d9%85-%d8%a7%d9%84%d8%a2%d9%84%d8%a9/
https://academy.hsoub.com/files/15-%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-%D8%A8%D9%84%D8%BA%D8%A9-%D8%A8%D8%A7%D9%8A%D8%AB%D9%88%D9%86/
/pages/write-for-us/write-for-us/
/pages/teach/
https://wiki.hsoub.com
https://academy.hsoub.com/register/
https://academy.hsoub.com/discover/
https://academy.hsoub.com/
/pages/about/
/pages/faq/
/pages/write-for-us/
/pages/teach/
/pages/terms/
/pages/privacy/
https://support.academy.hsoub.com
http://www.hsoub.com
http://creativecommons.org/licenses/by-nc-sa/4.0/
#
https://academy.hsoub.com/login/
https://academy.hsoub.com/register/
#
#
https://academy.hsoub.com
https://academy.hsoub.com/discover/
https://academy.hsoub.com/search/
#
#
http://twitter.com/HsoubAcademy
http://www.facebook.com/HsoubAcademy
https://www.youtube.com/channel/UCJv37tcBvJlBF2MoVMRMvbQ
https://academy.hsoub.com/programming/general/%D8%AA%D8%B9%D9%84%D9%85-%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D8%A9-r662/
https://wiki.hsoub.com
#
#
https://academy.hsoub.com/#
https://academy.hsoub.com/entrepreneurship/
https://academy.hsoub.com/freelance/
https://academy.hsoub.com/marketing/
https://academy.hsoub.com/programming/
https://academy.hsoub.com/design/
https://academy.hsoub.com/devops/
https://academy.hsoub.com/apps/
https://academy.hsoub.com/certificates/
#
#
https://academy.hsoub.com/questions/
https://academy.hsoub.com/questions/c5-entrepreneurship/
https://academy.hsoub.com/questions/c8-freelance/
https://academy.hsoub.com/questions/c7-marketing/
https://academy.hsoub.com/questions/c3-programming/
https://academy.hsoub.com/questions/c4-design/
https://academy.hsoub.com/questions/c6-devops/
https://academy.hsoub.com/questions/c9-apps/
https://academy.hsoub.com/questions/c10-certificates/
#
#
https://academy.hsoub.com/files/
https://academy.hsoub.com/files/c2-entrepreneurship/
https://academy.hsoub.com/files/c3-freelance/
https://academy.hsoub.com/files/c4-marketing/
https://academy.hsoub.com/files/c5-programming/
https://academy.hsoub.com/files/c6-design/
https://academy.hsoub.com/files/c7-devops/
#
#
https://academy.hsoub.com/store/
https://academy.hsoub.com/store/c1-%D8%AF%D9%88%D8%B1%D8%A7%D8%AA-%D8%AA%D8%B9%D9%84%D9%8A%D9%85%D9%8A%D8%A9/
#
#
https://academy.hsoub.com/store/gift-cards/
https://academy.hsoub.com/store/redeem/

 

  • 1
نشر

بالاضافة للطريقة السابقة يمكننا استخدام الكود التالي بسهولة:

#استدعاء المكتبات
from bs4 import BeautifulSoup
import requests
 
#العنوان الذي تريده
url = "https://academy.hsoub.com/questions/18269-%D9%83%D9%8A%D9%81%D9%8A%D8%A9-%D8%A7%D8%B3%D8%AA%D8%AE%D8%B1%D8%A7%D8%AC-%D8%AC%D9%85%D9%8A%D8%B9-%D8%B9%D9%86%D8%A7%D9%88%D9%8A%D9%86-url-%D8%AF%D8%A7%D8%AE%D9%84-%D8%B5%D9%81%D8%AD%D8%A9-%D8%A7%D9%84%D9%88%D9%8A%D8%A8-%D8%A8%D8%A7%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85-%D9%85%D9%83%D8%AA%D8%A8%D8%A9%C2%A0beautifulsoup-%D9%81%D9%8A-%D8%A8%D8%A7%D9%8A%D8%AB%D9%88%D9%86/"
 
# ارسال طلب لجلب المعلومات من الصفحة.
response = requests.get(url)
 
# الحصول على الكود من الصفحة
data = response.text
 
# تمرير ما تم الحصول عليه للمكتبة
soup = BeautifulSoup(data, 'lxml')
 
# الحصول على كل ال tags التي تبدا ب <a>.
#لاحظ ان هذا يحتوى على كل ال url بداخل html
tags = soup.find_all('a')
 
# طباعة كل اللينكات
for tag in tags:
    print(tag.get('href'))

لاحظ انه هذا يقوم بارجاع كل العناوين فداخل صفحة ال html والتي تكون بداخل <a> tag ، اي كل ال links الموجودة.

  • 2
نشر

يمكنك إستخراج كل الروابط في صفحة ما وتقسيم هذه الروابط إلى روابط داخلية internal links (روابط لصفحات أخرى أو أماكن مختلفة في نفس الصفحة) وروابط خارجية external links (روابط تؤدي إلى مواقع آخرى)، على النحو التالي:
 

# لعمل الطلبات 
import requests

# لإستخرج الروابط من مستند HTML
from bs4 import BeautifulSoup

# لإستخرج نطاق الموقع domain من الروابط
import urllib.parse

if __name__ == '__main__':
    user_input_url = "https://github.com"
    domain = urllib.parse.urlparse(user_input_url).netloc
    
    # فحص إتصال الإنترنت
    try:
        website_content = requests.get(user_input_url.strip()).text
    except:
        check_internet = requests.get('https://google.com').status_code
        
        if check_internet != requests.codes.ok:
            raise ConnectionError("ERROR: Check internet connection.")
    
    _soup = BeautifulSoup(website_content, features='lxml')
    internal_url_links = []
    external_url_links = []
    
    for link in _soup.find_all('a', href=True):
        if link.get('href'):
            url_domain = urllib.parse.urlparse(link.get('href')).netloc
            
            # Absolute links
            if domain == url_domain:
                internal_url_links.append(link.get('href'))
            
            # Relative links
            # كل الروابط النسبية تبدأ بأحد الرموز التالية
            elif link.get('href')[0] in ['/', '#', '?']:
                internal_url_links.append(urllib.parse.urljoin(user_input_url, link.get('href')))
            
            # external url
            # إذا كان طول الرابط أقل من 3 أحرف فهو رابط غير صالح
            elif domain != url_domain and len(link.get('href')) > 3:
                external_url_links.append(link.get('href'))
    
    print(internal_url_links, '\n')
    print(external_url_links, '\n')

 

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...