第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Python 訪問 Microsoft Sharepoint 文件和數(shù)據(jù)

使用 Python 訪問 Microsoft Sharepoint 文件和數(shù)據(jù)

富國滬深 2022-07-12 16:10:45
我正在使用 Microsoft 共享點。我有一個 url,通過使用該 url,我需要獲取總數(shù)據(jù),如照片、視頻、文件夾、子文件夾、文件、帖子等......并且我需要將這些數(shù)據(jù)存儲在數(shù)據(jù)庫(Sql server)中。我正在使用python。所以,請任何人建議我如何做到這一點,我是訪問共享點和工作這類事情的初學者。
查看完整描述

2 回答

?
冉冉說

TA貢獻1877條經(jīng)驗 獲得超1個贊

這是通過 Python 連接到共享點以及訪問文件列表、文件夾和 Sharepoint 的單個文件內容的入門代碼。您可以在此基礎上進行構建以滿足您的需求。


請注意,此方法適用于可通過 Internet 訪問的公共 Sharepoint 站點。對于托管在公司 Intranet 上的組織受限 Sharepoint 站點,我尚未測試此代碼。


您將不得不稍微修改 Sharepoint 文件的鏈接,因為您無法使用從 Web 瀏覽器復制的文件的 URL 地址直接訪問 Python 中的 Sharepoint 文件。



from office365.runtime.auth.authentication_context import AuthenticationContext

from office365.sharepoint.client_context import ClientContext

from office365.sharepoint.files.file import File 


####inputs########

# This will be the URL that points to your sharepoint site. 

# Make sure you change only the parts of the link that start with "Your"

url_shrpt = 'https://YourOrganisation.sharepoint.com/sites/YourSharepointSiteName'

username_shrpt = 'YourUsername'

password_shrpt = 'YourPassword'

folder_url_shrpt = '/sites/YourSharepointSiteName/Shared%20Documents/YourSharepointFolderName/'


#######################




###Authentication###For authenticating into your sharepoint site###

ctx_auth = AuthenticationContext(url_shrpt)

if ctx_auth.acquire_token_for_user(username_shrpt, password_shrpt):

  ctx = ClientContext(url_shrpt, ctx_auth)

  web = ctx.web

  ctx.load(web)

  ctx.execute_query()

  print('Authenticated into sharepoint as: ',web.properties['Title'])


else:

  print(ctx_auth.get_last_error())

############################

  

  

  

  

####Function for extracting the file names of a folder in sharepoint###

###If you want to extract the folder names instead of file names, you have to change "sub_folders = folder.files" to "sub_folders = folder.folders" in the below function

global print_folder_contents

def print_folder_contents(ctx, folder_url):

    try:

       

        folder = ctx.web.get_folder_by_server_relative_url(folder_url)

        fold_names = []

        sub_folders = folder.files #Replace files with folders for getting list of folders

        ctx.load(sub_folders)

        ctx.execute_query()

     

        for s_folder in sub_folders:

            

            fold_names.append(s_folder.properties["Name"])


        return fold_names


    except Exception as e:

        print('Problem printing out library contents: ', e)

######################################################

  

  

# Call the function by giving your folder URL as input  

filelist_shrpt=print_folder_contents(ctx,folder_url_shrpt) 


#Print the list of files present in the folder

print(filelist_shrpt)

現(xiàn)在我們能夠檢索和打印 Sharepoint 中特定文件夾中存在的文件列表,下面是訪問特定文件的文件內容并將其保存到知道 Sharepoint 中的文件名和路徑的本地磁盤的代碼。


#Specify the URL of the sharepoint file. Remember to change only the the parts of the link that start with "Your"

file_url_shrpt = '/sites/YourSharepointSiteName/Shared%20Documents/YourSharepointFolderName/YourSharepointFileName'


#Load the sharepoint file content to "response" variable

response = File.open_binary(ctx, file_url_shrpt)


#Save the file to your offline path

with open("Your_Offline_File_Path", 'wb') as output_file:  

    output_file.write(response.content)

您可以參考以下鏈接連接到 SQL Server 并將內容存儲在表中: 使用 Python 連接到 Microsoft SQL Server


https://datatofish.com/how-to-connect-python-to-sql-server-using-pyodbc/


查看完整回答
反對 回復 2022-07-12
?
PIPIONE

TA貢獻1829條經(jīng)驗 獲得超9個贊

您可能要考慮使用 Pysharepoint,它提供了簡單的界面來上傳和下載文件到 Python 中的 Sharepoint。


import pysharepoint as ps


sharepoint_base_url = 'https://<abc>.sharepoint.com/'

username = 'username'

password = 'password'


site = ps.SPInterface(sharepoint_base_url,username,password)


source_path = 'Shared Documents/Shared/<Location>'

sink_path = '/full_sink_path/'

filename = 'filename.ext'

sharepoint_site = 'https://<abc>.sharepoint.com/sites/<site_name>


site.download_file_sharepoint(source_path, sink_path,filename,sharepoint_site)

site.upload_file_sharepoint(source_path, sink_path,filename,sharepoint_site)


查看完整回答
反對 回復 2022-07-12
  • 2 回答
  • 0 關注
  • 1076 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號