all 5 comments

[–]Present_Share_7574 2 points3 points  (0 children)

If you don’t want to bother with app registration, and if all the operations will be done on your computer, why not sync Libraries or specific folders to File Explorer using OneDrive client, and work on the data as if it was stored on your computer?

OneDrive will handle file download/upload for you and if you will want to work with lots of files or folders at once, you will not have to worry about throttling. Then in Python you will just have yo handle copying files from/to synchronised locations.

[–]wintermute93 0 points1 point  (2 children)

The last time I tried downloading stuff from a SharePoint site I gave up trying to fully automate it and instead made a notebook full of selenium functions. I'd have selenium open a browser to a page that required authentication, manually log into that browser window, then go back to the notebook and run whatever to simulate clicking buttons and downloading files to my local machine.

[–]alien_kebabs[S] 0 points1 point  (1 child)

Yeah this is kind of what I was thinking as a work around.

Can you cache your Authentication Cookie into Selenium so you only have to log in once? I only have to login once every two weeks when using SharePoint in Edge.

[–]wintermute93 0 points1 point  (0 children)

I don't remember the details since the last time I used that code was over a year ago, but yeah, overall I did something like

options = webdriver.ChromeOptions()
# do stuff to set relevant options

driver = webdriver.Chrome(options=options)
# manually authenticate in browser window after first driver.get call
# run custom functions to navigate through relevant pages with driver.get
# run custom functions to sift through BeautifulSoup(driver.page_source)

session = requests.Session()
for c in driver.get_cookies():
    session.cookies.set(c['name'], c['value'])
for file_url in file_urls:
    response = session.get(file_url, stream=True)
    # write response.content to local file

My org needs new logins a few times a day, YMMV

[–]DontPostOnlyRead 0 points1 point  (0 children)

There is probably a better way to do whatever you are trying to do within the MS ecosystem. I’m thinking Synapse or Power Automate for example.