Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

google docs - Downloading a file with Powershell

The following Google Doc gets exported to CSV and is then downloaded automatically using a standard Web Browser: https://docs.google.com/spreadsheets/d/1wDD_Xm8IQYuYNefv9cOJ_7afTLImHgYA05pfN3qY63E/export?format=csv

I'm trying to download this file using Powershell without success. I tried using Invoke-Webrequest, Start-BitsTransfer and using a webrequest object but no luck there.

EDITED: changed url.

question from:https://stackoverflow.com/questions/51225598/downloading-a-file-with-powershell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Invoke-WebRequest comes with a parameter to store its result in a file: -OutFile

Invoke-WebRequest URL -OutFile c:file.ext

If you need authorization before you can send a request like this:

Invoke-WebRequest URL /* whatever is neccesary to login */ -SessionVariable MySession
Invoke-WebRequest URL -WebSession $MySession

To determine the layout of the form where the login happens, you can use Invoke-WebRequests return object. It'll collect information about forms and fields on the HTML (might be Windows only). Mileage of logging in may vary with things like Two-Factor-Auth active or not. Probably you can create some secret link to your file which does not need Auth or possibly google allows you to create a private access token of some sort, which can be send aus Authorization-Header alongside your request.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...