عرض مشاركة واحدة
قديم 22-11-2019, 06:17 PM كاتب الموضوع #10
Tq007
مشارك
 
الصورة الرمزية Tq007
 



افتراضي رد: بايثون -حذف كل شي بعد رمز معين ؟





SPOILER:
مشاهدة المشاركة الأصلية
iSR5
SPOILER:





videoId هذا داخل مصفوفة الـ contentDetails


فانت بتعمل كذا :

كود:
data["contentDetails"]["videoId"]

كود:
import json

json_data = """
 {
  "contentDetails" : {
    "videoId" : "rrrrrrrrrrrrr",
    "videoPublishedAt" : "2000-11-0000:0:0.000Z"
  },
  "etag" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
  "id" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
  "kind" : "youtube#playlistItem",
  "snippet" : {
    "channelId" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
    "channelTitle" : "rrrrrrrrr",
    "description" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
    "playlistId" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr-rr",
    "position" : 2,
    "publishedAt" : "2000-00-02T00:00:00.000Z",
    "resourceId" : {
      "kind" : "youtube#video",
      "videoId" : "rrrrrrrrrrrrrrr"
    },
    "thumbnails" : {
      "default" : {
        "height" : 90,
        "url" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
        "width" : 120
      },
      "high" : {
        "height" : 360,
        "url" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
        "width" : 480
      },
      "medium" : {
        "height" : 180,
        "url" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
        "width" : 320
      },
      "standard" : {
        "height" : 480,
        "url" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
        "width" : 640
      }
    },
    "title" : "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
  },
  "status" : {
    "privacyStatus" : "public"
  }
}
"""

data = json.loads(json_data)

print(data["contentDetails"]["videoId"])



يعطي ايرور
TypeError: list indices must be integers or slices, not str
حليتها ب اضافه الي بالاحمر
لاكن ماراح يطبع الا الرقم الي تحطه
كود:
#print (data[0]['contentDetails']['videoId'])
عشان تطبع كل شي لازم تسوي لوب
كود:
print([data_item['contentDetails']["videoId"] for data_item in data])
الحين كيف احط كل videoId في رابط ؟ (1500 واحد)!
ابي اقسم كل 25 في صفحه لحال منين ابدا
youtbe.com/dddd/watch=/+videoId+/ss

طبعا انا افتحه عن طريق
كود:
webbrowser.open_new(a_website)

 

 

التوقيع
اقتبس ردي اذا بترد علي

Tq007 غير متصل  
Yes No
رد مع اقتباس