VB6 - 如何将URL内容存储在字符串中并另存为文件(例如.txt)

时间:2016-08-08 15:18:05

标签: vb6

Option Explicit

Public Sub save_url_contents_as_text()  
    Dim MyUrl As String  
    Dim MyFile As Object    'store the text file here  
    Dim tempstring As String

    MyUrl = "www.AnythingIWantToPutHere"

    'I want your help here. Something Like a function  
    tempstring = geturltext(MyUrl)

    'I want to save the URL text contents here  
    MyFile = tempstring

End Sub

1 个答案:

答案 0 :(得分:0)

直接来自here。根据需要更改URL和文件名。此调用将URL的内容写入磁盘文件。

  

此示例说明如何使用URLDownloadToFile API function将URL中的文件下载到Visual Basic 6中的文件中。

Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Sub Form_Load()
  ' Download the file.
  URLDownloadToFile 0, _
    "http://www.vb-helper.com/vbhelper_425_64.gif", _
    "C:\vbhelper_425_64.gif", 0, 0

End Sub