扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python鎬庝箞閫氳繃url涓嬭浇鏂囦欢

扬州沐宇科技
2024-03-22 15:17:42
python

浣犲彲浠ヤ娇鐢?code>urllib鎴?code>requests妯″潡鏉ヤ笅杞芥枃浠躲€備互涓嬫槸浣跨敤urllib妯″潡鐨勭ず渚嬩唬鐮?

import urllib.request

url = "https://example.com/sample.jpg"
filename = "sample.jpg"

urllib.request.urlretrieve(url, filename)
print("鏂囦欢宸蹭笅杞?quot;)

濡傛灉浣犲笇鏈涗娇鐢?code>requests妯″潡鏉ヤ笅杞芥枃浠讹紝鍙互鍙傝€冧互涓嬬ず渚嬩唬鐮?

import requests

url = "https://example.com/sample.jpg"
filename = "sample.jpg"

response = requests.get(url)
with open(filename, "wb") as file:
    file.write(response.content)

print("鏂囦欢宸蹭笅杞?quot;)

杩欎袱绉嶆柟娉曢兘鍙互鐢ㄦ潵浠嶶RL涓嬭浇鏂囦欢锛屼綘鍙互鏍规嵁鑷繁鐨勫亸濂介€夋嫨鍏朵腑涓€绉嶃€?/p>

扫码添加客服微信