VB6收集更新的网址

时间:2015-09-23 06:44:43

标签: vb6

我有一个我已经生成的网址列表。问题是,我相信该网站使用php来生成他们的页面,因为当其中一个地址被导航时,该网站会在该地址中添加一个子目录。

例如,如果我导航到...

http://www.wowhead.com/item=43

地址变为......

http://www.wowhead.com/item=43/squires-boots

每个项目编号的子目录都不同。

我想要做的是收集我为我生成的每个地址重定向的网址,并且因为有很多地址(大约127,000),我正在寻找以最快的方式。

目前,我正在使用webbrowser控件(wb)

Dim l As Long
Dim ff As Long
Dim strPerkText as String
Dim sPaths() As String
Dim lngTimer As Long
Const lngWait As Long = 5

strPerkText = OpenFile    'using a sub to get this data

sPaths = Split(strPerkText, vbCrLf)

ff = FreeFile

Open App.Path & "\ItemListURLs.txt" For Output As #ff
    For l = 0 To UBound(sPaths)
        lngTimer = Timer
        wb.Navigate2 sPaths(l)
        Do While wb.READYSTATE <> READYSTATE_COMPLETE
            If Timer - lngTimer >= lngWait Then
                Exit Do
            End If
            DoEvents
        Loop
        Write #ff, wb.LocationURL
        DoEvents
    Next l
Close #ff

lngWait是我必须等待wb使用新网址更新的时间,每页大约5秒,禁止任何错误。这意味着用我现在制作程序的方式完成所有工作大约需要一周的时间。我不确定使用不同的控件,API或纯本机代码是否可以更快地完成此操作。

欢迎所有建议。

1 个答案:

答案 0 :(得分:0)

我测试了Inet控件。它只需要花费浏览器的一小部分时间完成工作,而且我不必担心网站可能会抛出的任何错误。对于其他寻找类似内容的人来说,这里是我使用的代码:

Dim l As Long
Dim sPaths() As String
Dim b() As Byte
Dim strFileName As String
'OpenFile is a function that opens the specific 
'file with the list of URLs    
If strPerkText = "" Then
    strPerkText = OpenFile
End If
'split up the list
sPaths = Split(strPerkText, vbCrLf)
'progress bar - set to 0
pbrGo.Value = 0
'itterate through the list
For l = 0 To UBound(sPaths)
    'make sure there is a path to use
    If sPaths(l) <> "" Then
        'set the path to the Inet control
        Inet.URL = sPaths(l)
        'Retrieve the HTML data into a byte array.
        b() = Inet.OpenURL(Inet.URL, icByteArray)
        'GetFileName captures the end of the URL back to the last /
        strFileName = GetFileName(Inet.URL)
        'txtCollect.text contains the path where the files will be saved
        'adjust the filename to include the path and extension
        strFileName = txtCollect.Text & strFileName & ".txt"
        'Create a local file from the retrieved data.
        Open strFileName For Binary Access Write As #1
            Put #1, , b()
        Close #1
        'update progress bar
        pbrGo.Value = (l / UBound(sPaths)) * 100
        DoEvents
    End If
Next l
beep
MsgBox "Downloading Files Complete"