프로그래밍/VB.NET
[VB.NET] 구글 드라이브 파일 다운로드
F0X
2022. 5. 25. 16:24
Public Class DownloadFileThread
<DllImport("urlmon.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, EntryPoint:="URLDownloadToFileW", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function urldownloadtofile(ByVal pCaller As Integer, ByVal szurl As String, ByVal szfilename As String, ByVal reserved As Integer, ByVal callback As Integer) As Integer
End Function
End Class
WebBrowser1.Naviagte("https://drive.google.com/uc?id=각자 파일마다 다르니 참고&export=download")
'공유 링크가 아니라 공유 링크에서 다운로드 버튼을 눌렀을 때 링크를 넣으셔야 합니다.
Dim strRes as string = WebBrowser1.Document.Body.InnerHtml
'strRes 변수에 HTML 소스 집어넣기
Dim strHTML as string = Split(Split(Split(strRes, "uc-name-size")(1), """>")(1), "</A>")(0)
'파일명을 strHTML 변수에 값을 담아준다.
strRes = "https://drive.google.com/uc?export=download&confirm="& Split(Split(strRes, "confirm=")(1), "&")(0) & "&id=각자 파일마다 다르니 참고"
'Confirm 값은 항상 바뀌어서 파싱으로 값을 가져옵니다.
DownloadFileThread.urldownloadtofile(0, strRes, Application.StartupPath & "\" & strHTML, 0, 0)
'파일 다운로드를 진행할 때 사용하는 코드입니다.
'strRes = 파일 주소
'Application.StartupPath & "\" & strHTMl = 파일을 실행시킨 경로에 파일을 다운로드한다.
구글 드라이브에서 용량이 어느 정도 있는 파일을 다운로드하려면 웹 세션을 유지시켜줘야 한다.