ما هذا الخطأ Traceback (most recent call last): File…
- User
ما هذا الخطأ Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), main.dict) File "", line 6 video_urls = input(“Enter urls separated by space: “).split() ^ SyntaxError: invalid character '“' (U+201C)
[Program finished]
- Assistant
الخطأ هو SyntaxError والذي يعني أن هناك خطأ في صياغة الكود. في هذه الحالة، الخطأ هو invalid character '“' (U+201C) والذي يعني أن هناك حرف غير صالح في السطر 6 في الكود. يجب استخدام علامات الاقتباس الصحيحة في الأسطر التي تستخدم النصوص مثل input() و print(). في هذه الحالة، يجب استخدام علامات الاقتباس المزدوجة "" بدلا من علامات الاقتباس المستخدمة في السطر الخاطئ.
- User
هذا هو الكود صحح الخطا import requests from bs4 import BeautifulSoup import os from tqdm import tqdm
video_urls = input(“Enter urls separated by space: “).split() if not os.path.exists(“tiktok_videos”): os.makedirs(“tiktok_videos”)
for url in tqdm(video_urls): try: res = requests.get(url) soup = BeautifulSoup(res.text, ‘html.parser’) video_url = soup.find(‘video’).attrs[‘src’] with open(‘temp_video.mp4’, ‘wb’) as f: f.write(requests.get(video_url).content) video_name = url.split(”/”)[-1] + “.mp4” with open(f"tiktok_videos/{video_name}“, ‘wb’) as f: f.write(requests.get(video_url).content) except: print(f"Failed to download video at {url}”)
print(“Finished downloading videos!”)
- Assistant
import requests from bs4 import BeautifulSoup import os from tqdm import tqdm
video_urls = input("Enter urls separated by space: ").split() if not os.path.exists("tiktok_videos"): os.makedirs("tiktok_videos")
for url in tqdm(video_urls): try: res = requests.get(url) soup = BeautifulSoup(res.text, 'html.parser') video_url = soup.find('video').attrs['src'] with open('temp_video.mp4', 'wb') as f: f.write(requests.get(video_url).content) video_name = url.split("/")[-1] + ".mp4" with open(f"tiktok_videos/{video_name}", 'wb') as f: f.write(requests.get(video_url).content) except: print(f"Failed to download video at {url}")
print("Finished downloading videos!")
- User
وما الخطأ هنا أيضاً Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), main.dict) File "", line 7 video_urls = input(“Enter urls separated by space: “).split() ^ SyntaxError: invalid character '“' (U+201C)
[Program finished]
- Assistant
الخطأ هنا هو SyntaxError وهو نفس الخطأ السابق والذي يشير إلى أن هناك حرفًا غير صالح في السطر 7. يجب استخدام علامات الاقتباس الصحيحة في الكود. يمكن حل هذا الخطأ بتعديل علامات الاقتباس المستخدمة في input() واستخدام علامات الاقتباس المزدوجة "" بدلاً منها.
الكود بعد التعديل:
import requests from bs4 import BeautifulSoup import os from tqdm import tqdm video_urls = input("Enter urls separated by space: ").split() if not os.path.exists("tiktok_videos"): os.makedirs("tiktok_videos") for url in tqdm(video_urls): try: res = requests.get(url) soup = BeautifulSoup(res.text, 'html.parser') video_url = soup.find('video').attrs['src'] with open('temp_video.mp4', 'wb') as f: f.write(requests.get(video_url).content) video_name = url.split("/")[-1] + ".mp4" with open(f"tiktok_videos/{video_name}", 'wb') as f: f.write(requests.get(video_url).content) except: print(f"Failed to download video at {url}") print("Finished downloading videos!") - User
و ما هذا الخطأ Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), main.dict) File "", line 6 video_urls = input(“Enter urls separated by space: “).split() ^ SyntaxError: invalid character '“' (U+201C)
[Program finished]
- Assistant
الخطأ هو SyntaxError وتم تحديده بنفس الطريقة حيث يوجد حرف غير صالح في السطر 6. الحل هو استخدام العلامات الصحيحة في الأسطر التي تحتوي على النصوص. يمكن استخدام علامات الاقتباس المزدوجة "" بدلاً من علامات الاقتباس الغير صحيحة التي تم استخدامها.
الكود بعد التعديل:
import requests from bs4 import BeautifulSoup import os from tqdm import tqdm video_urls = input("Enter urls separated by space: ").split() if not os.path.exists("tiktok_videos"): os.makedirs("tiktok_videos") for url in tqdm(video_urls): try: res = requests.get(url) soup = BeautifulSoup(res.text, 'html.parser') video_url = soup.find('video').attrs['src'] with open('temp_video.mp4', 'wb') as f: f.write(requests.get(video_url).content) video_name = url.split("/")[-1] + ".mp4" with open(f"tiktok_videos/{video_name}", 'wb') as f: f.write(requests.get(video_url).content) except: print(f"Failed to download video at {url}") print("Finished downloading videos!") - User
وما الخطأ Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), main.dict) File "", line 6 video_urls = input(“Enter urls separated by space: “).split() ^ SyntaxError: invalid character '“' (U+201C)
[Program finished]
- Assistant
الخطأ هو SyntaxError وهو نفس الخطأ السابق والذي يشير إلى وجود حرف غير صالح في السطر 6. يجب استخدام علامات الاقتباس الصحيحة في الأسطر التي تحتوي على النصوص. يمكن استخدام علامات الاقتباس المزدوجة "" بدلاً من علامات الاقتباس الغير صحيحة التي تم استخدامها.
الكود بعد التعديل:
import requests from bs4 import BeautifulSoup import os from tqdm import tqdm video_urls = input("Enter urls separated by space: ").split() if not os.path.exists("tiktok_videos"): os.makedirs("tiktok_videos") for url in tqdm(video_urls): try: res = requests.get(url) soup = BeautifulSoup(res.text, 'html.parser') video_url = soup.find('video').attrs['src'] with open('temp_video.mp4', 'wb') as f: f.write(requests.get(video_url).content) video_name = url.split("/")[-1] + ".mp4" with open(f"tiktok_videos/{video_name}", 'wb') as f: f.write(requests.get(video_url).content) except: print(f"Failed to download video at {url}") print("Finished downloading videos!") - User
لماذا تظهر لي نفس النتيجه رغم التصحيح الكود
- Assistant
قد يكون السبب في ذلك هو عدم حفظ التغييرات التي قمت بها في ملف الكود قبل تشغيله مرة أخرى. يجب حفظ الملف بعد إجراء التعديلات قبل تشغيل البرنامج مرة أخرى. بمجرد حفظ الملف بالشكل الصحيح، يجب أن تتمكن من تشغيل البرنامج الجديد بدون أية أخطاء.
- User
هل هذا الكود صحيح لكي يشتغل علي pydroid3
- Assistant
نعم، الكود الذي قدمته يجب أن يعمل بشكل صحيح على Pydroid 3، ولكن يجب التأكد من تحديث حزم البرامج اللازمة وتثبيتها بشكل صحيح. قم بتثبيت حزمة tqdm باستخدام pip، عن طريق تشغيل الأمر
pip install tqdmفي وحدة التحكم (console) في Pydroid 3. قم أيضًا بتحديث حزمة requests باستخدامpip install --upgrade requests. - User
ما الحزم المطلوب تثبيتها لتشغيل الاسكربت
- Assistant
يعتمد الحزم التي تحتاج إليها على المكتبات التي يتم استخدامها في البرنامج الذي تريد تشغيله. في هذا السياق، يحتاج البرنامج إلى حزمة requests و Beautiful Soup و os و tqdm.
يمكن استخدام الأمر
pip install package_nameلتثبيت حزم البرامج المطلوبة. يجب استخدام console في Pydroid 3 لتنفيذ هذه الأوامر. يمكن استخدام الأمرpip install beautifulsoup4لتثبيت حزمة BeautifulSoup، ويمكن استخدامpip install requestsلتثبيت حزمة requests، ويمكن استخدامpip install tqdmلتثبيت حزمة tqdm. لا تحتاج حزمة OS إلى تثبيت إذا كنت تستخدم Pydroid 3.