Telegram Group & Telegram Channel
🇩🇪 بسته URLLIB

❗️ این بسته که برای کار با URLها از چندین ماژول استفاده می‌کند که عبارتند از:

urllib.request که برای باز کردن و خواندن URLها استفاده می‌شود.

urllib.error که برای مدیریت کردن خطاهایی است که توسط  urllib.request بوجود آمده‌اند.

🤔 ماژول urllib.request رابطی بسیار ساده برای ایجاد درخواست‌ها بوجود می‌آورد و هم‌چنین برای مدیریت‌کردن احراز هویت‌ گزینه‌های بیشتری در اختیار برنامه نویس قرار می‎دهد.

↙️ در کد زیر درخواستی توسط متد urlopen فرستاده شد:

import urllib

req = urllib.request.urlopen('https://example.ir')

print(req.status)

🔅 دریافت منبع از اینترنت هم توسط متد urlretrieve انجام می‌شود.

 

⭕️ مثال تفاوت دریافت عکس با Urllib و Requests :

import urllib

url = 'https://www.python.org/static/opengraph-icon-200x200.png'

urllib.request.urlretrieve(url, "image-urllib.png")



import requests

url = 'https://www.python.org/static/opengraph-icon-200x200.png'

r = requests.get(url)

with open("image-requests.png", "wb") as code:

    code.write(r.content)



tg-me.com/python12/1374
Create:
Last Update:

🇩🇪 بسته URLLIB

❗️ این بسته که برای کار با URLها از چندین ماژول استفاده می‌کند که عبارتند از:

urllib.request که برای باز کردن و خواندن URLها استفاده می‌شود.

urllib.error که برای مدیریت کردن خطاهایی است که توسط  urllib.request بوجود آمده‌اند.

🤔 ماژول urllib.request رابطی بسیار ساده برای ایجاد درخواست‌ها بوجود می‌آورد و هم‌چنین برای مدیریت‌کردن احراز هویت‌ گزینه‌های بیشتری در اختیار برنامه نویس قرار می‎دهد.

↙️ در کد زیر درخواستی توسط متد urlopen فرستاده شد:

import urllib

req = urllib.request.urlopen('https://example.ir')

print(req.status)

🔅 دریافت منبع از اینترنت هم توسط متد urlretrieve انجام می‌شود.

 

⭕️ مثال تفاوت دریافت عکس با Urllib و Requests :

import urllib

url = 'https://www.python.org/static/opengraph-icon-200x200.png'

urllib.request.urlretrieve(url, "image-urllib.png")



import requests

url = 'https://www.python.org/static/opengraph-icon-200x200.png'

r = requests.get(url)

with open("image-requests.png", "wb") as code:

    code.write(r.content)

BY پایتون / python




Share with your friend now:
tg-me.com/python12/1374

View MORE
Open in Telegram


پایتون python Telegram | DID YOU KNOW?

Date: |

Mr. Durov launched Telegram in late 2013 with his brother, Nikolai, just months before he was pushed out of VK, the Russian social-media platform he founded. Mr. Durov pitched his new app—funded with the proceeds from the VK sale—less as a business than as a way for people to send messages while avoiding government surveillance and censorship.

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

پایتون python from us


Telegram پایتون / python
FROM USA