gpt4 book ai didi

戈朗 "Log in to the site and download the xls file"?

转载 作者:数据小太阳 更新时间:2023-10-29 03:47:31 29 4
gpt4 key购买 nike

<分区>

告诉我如何使用Golang登录网站。下载xls文件是得到了,但是为了在Excel表格中有数据,需要登录网站。该站点位于公司的服务器上。如果你能告诉你怎么做。

例如,我用来执行此操作的 VBA 代码。

Set oFields = CreateObject("Scripting.Dictionary")
With oFields
.Add "login", "sdiscor"
.Add "password", "sdiscor"
End With
For Each sName In oFields
oFields(sName) = sName & "=" & EncodeUriComponent(oFields(sName))
Next
sPayLoad = Join(oFields.Items(), "&")

With CreateObject("MSXML2.XMLHTTP")
.Open "POST", "http://effect.gvc.oao.rzd/cgi_bin/effect_access.pl?", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Content-Length", LenB(sPayLoad)
.Send (sPayLoad)

Do While .readyState <> 4
DoEvents
Loop

webLink = "http://effect.gvc.oao.rzd/effect/table/***&LOGIN=&PASSWORD="
vLocalFile = ThisWorkbook.Path & "\SIS-Effect.xls"

.Open "GET", webLink, True
.Send

Do While .readyState <> 4
DoEvents
Loop

oResp = .responseBody

vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
End With

感谢 leolara!!!最终代码

func main() {
urlLogin := "http://effect.gvc.oao.rzd/cgi_bin/effect_access.pl?"
urlDownload := "http://effect.gvc.oao.rzd/effect/table/OZODO10U.XLS?DAT=2019.03.04&LOGIN=&PASSWORD="

cookieJar, _ := cookiejar.New(nil)

client := &http.Client{Jar: cookieJar,}

_, err := client.PostForm(urlLogin,
url.Values{"login": {"sdiscor"}, "password": {"sdiscor"}})
if err != nil {
fmt.Println("Error while downloading", urlLogin, "-", err)
return
}

fileName := "1.xls"
fmt.Println("Downloading", urlDownload, "to", fileName)
output, err := os.Create(fileName)
if err != nil {
fmt.Println("Error while creating", fileName, "-", err)
return
}
defer output.Close()

resp, err := client.Get(urlDownload)
if err != nil {
fmt.Println("Error while downloading", urlDownload, "-", err)
return
}
defer resp.Body.Close()

n, err := io.Copy(output, resp.Body)
if err != nil {
fmt.Println("Error while downloading", urlDownload, "-", err)
return
}

fmt.Println(n, "bytes downloaded.")

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com