加入timer,commandbutton,text private sub command1_click() webbrowser1.navigate http://www.sohu.com/ timer1.enabled=true end subprivate sub timer1_timer() dim doc,objhtml as object dim i as integer dim strhtml as stringif not webbrowser1.busy then set doc=webbrowser1.document i=0 set objhtml=doc.body.createtextrange() if not isnull(objhtml) then text1.text=objhtml.htmltext end if timer1.enabled=false end if end sub
WebBrowser 控件效果非常不好 他会自己下载 flash 和图片 等浪费网络带宽导致效率极其低下,毫无意义而且用了 time 控件更加导致效率低这个毫无意义!!!
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 Command1_Click() Dim sourceUrl As String Dim targetFile As String Dim hfile As Long
URLDownloadToFile: 说明: Downloads bits from the Internet and saves them to a file.适用于: VB4-32,5,6 声明: 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 操作系统支持: Requires Windows NT 4.0 or later; Requires Windows 95 or later 库文件 Urlmon 参数:pCaller: Address of the controlling IUnknown interface of the calling Microsoft?ActiveX?component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download. szURL: Address of a string value containing the URL to be downloaded. Cannot be set to NULL. szFileName: Address of a string value containing the name of the file to create for bits that come from the download. dwReserved: Reserved. Must be zero. lpfnCB: Address of the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL. 返回值: Returns one of the following values: E_OUTOFMEMORY The buffer length is invalid or there was insufficient memory to complete the operation. S_OK The operation succeeded. 具体的解释我就不翻译了
试试这个 用IE来下载 Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long Private Sub Command1_Click()
End SubPrivate Sub Form_Load() Text1.Text = "http://www.chat.ru/~softdaily/fo-ag162.zip" Form1.Caption = "Audiograbber 1.62 Full" Text2.Text = "http://www6.50megs.com/audiograbber/demos/cr-ag161.zip" End Sub
private sub command1_click()
webbrowser1.navigate http://www.sohu.com/
timer1.enabled=true
end subprivate sub timer1_timer()
dim doc,objhtml as object
dim i as integer
dim strhtml as stringif not webbrowser1.busy then
set doc=webbrowser1.document
i=0
set objhtml=doc.body.createtextrange()
if not isnull(objhtml) then
text1.text=objhtml.htmltext
end if
timer1.enabled=false
end if
end sub
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 Command1_Click() Dim sourceUrl As String
Dim targetFile As String
Dim hfile As Long
sourceUrl = "http://123.com/123.asp?姓名=张&性别=女"
targetFile = "c:\temp\xxx.html"
hfile = URLDownloadToFile(0&, sourceUrl, targetFile, 0&, 0&)
End Sub
但是
如果能提供详细的URLDownloadToFile介绍更好
比如
如何我知道已经下载完成了?
如何知道下载的进度?
如何将下载的文本实时的显示在文本框?
如何假设下载了一部分已经得到我需要的数据,我要停止下载,然后去下载另一个页面?
如何知道该连接无效不能下载?
希望大家教我,我将 100 分送上,如果分数不够,我还有很多!
说明:
Downloads bits from the Internet and saves them to a file.适用于:
VB4-32,5,6
声明:
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 操作系统支持:
Requires Windows NT 4.0 or later; Requires Windows 95 or later 库文件
Urlmon
参数:pCaller:
Address of the controlling IUnknown interface of the calling Microsoft?ActiveX?component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download. szURL:
Address of a string value containing the URL to be downloaded. Cannot be set to NULL. szFileName:
Address of a string value containing the name of the file to create for bits that come from the download. dwReserved:
Reserved. Must be zero.
lpfnCB:
Address of the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL.
返回值:
Returns one of the following values:
E_OUTOFMEMORY
The buffer length is invalid or there was insufficient memory to complete the operation.
S_OK
The operation succeeded.
具体的解释我就不翻译了
用IE来下载
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
Private Sub Command1_Click()
Dim sDownload As String
sDownload = StrConv(Text1.Text, vbUnicode)
Call DoFileDownload(sDownload)
End SubPrivate Sub Form_Load()
Text1.Text = "http://www.chat.ru/~softdaily/fo-ag162.zip"
Form1.Caption = "Audiograbber 1.62 Full"
Text2.Text = "http://www6.50megs.com/audiograbber/demos/cr-ag161.zip"
End Sub
而且
还有很多 ping 不通,但是可以访问的网址
Xcs = Xcs + 1
hfile = URLDownloadToFile(0&, sourceUrl, targetFile, 0&, 0&)
If hfile = 0 Then '如果下载完成就减少一个
Xcs = Xcs - 1
End If我希望借此来控制同时下载的文件数但是代码
hfile = URLDownloadToFile(0&, sourceUrl, targetFile, 0&, 0&)
好像根本不需要时间Xcs = Xcs + 1
到
Xcs = Xcs - 1
快得让我难以置信■请问如何构造代码才能在下载之前 +1 下载完成后 -1 ?
■问题二
如何将下载的网页(其实就是文本字符)赋值给一个变量,而不是保存到硬盘上?
因为如果下载页面较多,将导致频繁写入和读取
影响运行速度和损伤硬盘
请问有什么好办法同时调用 若干个 URLDownloadToFile 下载不同的页面 ?我希望能达到每秒下载 10-100 个页面请大家给点提示!