Certainly, we can modify the code to handle different types of image sources and extract the extension accordingly. Here's an updated version of the code that should handle both URL and data URI sources and extract the proper extension:
```python
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
import csv
import requests
import base64
from io import BytesIO
from PIL import Image
from bs4 import BeautifulSoup
from urllib.parse import urlparse, urljoin

# Set up Blob Storage connection
blob_connection_string = "<your-connection-string>"
blob_service_client = BlobServiceClient.from_connection_string(blob_connection_string)
container_name = "<your-container-name>"
container_client = blob_service_client.get_container_client(container_name)

# Set up SQL connection
import pyodbc
server = "<your-server-name>.database.windows.net"
database = "<your-db-name>"
username = "<your-username>"
password = "<your-password>"
driver= '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)

# Define function to extract image extension
def get_image_extension(uri):
    try:
        # Check for data URI
        if uri.startswith("data:image"):
            extension = uri.split(";")[0].split("/")[-1]
        else:
            # Get image format from response headers
            response = requests.head(uri)
            content_type = response.headers["content-type"]
            extension = content_type.split("/")[-1]
    except Exception as e:
        print(f"Error extracting image extension: {e}")
        extension = "jpg"  # Default to jpg extension
    return extension

# Define function to upload image to Blob Storage
def upload_image_to_blob(image_data, id):
    extension = get_image_extension(image_data)
    blob_name = f"{id}.{extension}"
    blob_client = container_client.get_blob_client(blob_name)
    try:
        # Check if blob already exists, overwrite if it does
        blob_client.delete_blob()
    except:
        pass
    blob_client.upload_blob(image_data, overwrite=True)
    blob_url = f"https://{blob_service_client.account_name}.blob.core.windows.net/{container_name}/{blob_name}"
    return blob_url

# Define function to scrape profile photo and upload to Blob Storage
def scrape_profile_photo_and_upload(profile_url, id):
    try:
        # Get profile page HTML and extract photo URL
        response = requests.get(profile_url)
        soup = BeautifulSoup(response.content, "html.parser")
        img_tag = soup.find("img")
        if img_tag is None:
            raise Exception("No profile photo found")
        photo_url = img_tag.get("src")
        if not photo_url:
            raise Exception("No profile photo found")
        if photo_url.startswith("data:image"):
            # Handle data URI image source
            image_data = BytesIO(base64.b64decode(photo_url.split(",")[-1]))
        else:
            # Handle URL image source
            image_response = requests.get(urljoin(profile_url, photo_url))
            image_data = BytesIO(image_response.content)
        # Upload image to Blob Storage
        blob_url = upload_image_to_blob(image_data, id)
        return blob_url
    except Exception as e:
        print(f"Error scraping profile photo: {e}")
        return None

# Read CSV file from Blob Storage
csv_url = "<your-csv-file-url>"
csv_blob_client = container_client.get_blob_client(csv_url)
csv_content = csv_blob_client.download_blob().content_as_text()
reader = csv.reader(csv_content.splitlines(), delimiter=',')
next(reader)  # Skip header row
```
물론 다양한 유형의 이미지 소스를 처리하고 그에 따라 확장자를 추출하도록 코드를 수정할 수 있습니다. 다음은 URL 및 데이터 URI 소스를 모두 처리하고 적절한 확장자를 추출하는 코드의 업데이트 버전입니다:'''pythonazure.storage.blob에서 BlobServiceClient, BlobClient, ContainerClient를 가져옵니다.가져오기 CSV요청 가져오기import base64io에서 BytesIO를 가져옵니다.PIL에서 이미지 가져오기bs4에서 BeautifulSoup를 가져옵니다.urllib.parse에서 urlparse, urljoin을 가져옵니다.# 블롭 스토리지 연결 설정blob_connection_string = "<귀하의 연결 문자열>"blob_service_client = BlobServiceClient.from_connection_string(blob_connection_string)container_name = "<귀하의 컨테이너 이름>"container_client = blob_service_client.get_container_client(container_name)# SQL 연결 설정import pyodbcserver = "<귀하의 서버 이름>.database.windows.net"database = "<귀하의 데이터베이스 이름>"사용자 이름 = "<귀하의 사용자 이름>"password = "<귀하의 비밀번호>"driver = '{ODBC 드라이버 17 for SQL Server}'cnxn = pyodbc.connect('DRIVER='+드라이버+';SERVER='+서버+';PORT=1433;DATABASE='+데이터베이스+';UID='+사용자명+';PWD='+비밀번호')# 이미지 확장자를 추출하는 함수 정의def get_image_extension(uri):    try:        # 데이터 URI 확인        if uri.startswith("data:image"):            extension = uri.split(";")[0].split("/")[-1]        else:            # 응답 헤더에서 이미지 형식 가져오기            response = requests.head(uri)            content_type = response.headers["content-type"]            extension = content_type.split("/")[-1]    예외를 e로 제외합니다:        print(f"이미지 확장자 추출 오류: {e}")        extension = "jpg" # 기본값은 jpg 확장자    반환 확장자# 블롭 스토리지에 이미지를 업로드하는 함수를 정의합니다.def upload_image_to_blob(image_data, id):    extension = get_image_extension(image_data)    blob_name = f"{id}.{extension}"    blob_client = container_client.get_blob_client(blob_name)    try:        # 블롭이 이미 존재하는지 확인하고, 존재하면 덮어씁니다.        blob_client.delete_blob()    예외:        pass    blob_client.upload_blob(image_data, overwrite=True)    blob_url = f"https://{blob_service_client.account_name}.blob.core.windows.net/{container_name}/{blob_name}"    반환 blob_url# 프로필 사진을 스크랩하여 블롭 스토리지에 업로드하는 함수를 정의합니다.def scrape_profile_photo_and_upload(profile_url, id):    try:        # 프로필 페이지 HTML을 가져와 사진 URL 추출        response = requests.get(profile_url)        soup = BeautifulSoup(response.content, "html.parser")        img_tag = soup.find("img")        img_tag가 None이면            예외("프로필 사진을 찾을 수 없습니다") 발생        photo_url = img_tag.get("src")        photo_url이 아니라면            Exception("프로필 사진을 찾을 수 없습니다") 발생        if photo_url.startswith("data:image"):            # 데이터 URI 이미지 소스 처리            image_data = BytesIO(base64.b64decode(photo_url.split(",")[-1]))        else:            # URL 이미지 소스 처리            image_response = requests.get(urljoin(profile_url, photo_url))            image_data = BytesIO(image_response.content)        # 블롭 스토리지에 이미지 업로드        blob_url = upload_image_to_blob(image_data, id)        반환 blob_url    예외를 e로 제외합니다:        print(f"프로필 사진 스크래핑 오류: {e}")        반환 없음# 블롭 스토리지에서 CSV 파일 읽기csv_url = "<귀하의-csv-file-url>"csv_blob_client = container_client.get_blob_client(csv_url)csv_content = csv_blob_client.download_blob().content_as_text()reader = csv.reader(csv_content.splitlines(), 구분자=',')next(reader) # 헤더 행 건너뛰기```