替网友问的:求助!我想用VB编写一个组件,实现抓取网页的功能,该怎么做?用哪个API函数?高分!

xxlroad 2004-10-21 10:31:30
http://community.csdn.net/Expert/topic/3466/3466641.xml?temp=8.596438E-02
我想用VB编写一个组件,实现抓取网页的功能,该怎么做?用哪个API函数?

作  者: elongnet618 (飞翔) 你说可以给分的时候,给我qq发个消息和这个地址。
...全文
224 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
elongnet618 2004-10-26
  • 打赏
  • 举报
回复
to xxlroad(土八路)
我的MSN:flysky618@hotmailc.com
liujinhuagirl 2004-10-26
  • 打赏
  • 举报
回复
谢谢!
sakurako 2004-10-26
  • 打赏
  • 举报
回复
'函数名: DownloadFile
'功能: 下载指定URL的文件到硬盘目录
'作者: Sakurako
'参数: SourceURL:网络上的文件地址
' FileName:要保存的文件路径 文件名
'返回值: 成功:True;失败:False
'测试状态: 已测试
'时间: 2004-10-06
'其他:
Private Declare Function URLDownloadToFile Lib "urlmon.dll" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwResv As Long, ByVal lpfnCB As Long) As Long
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const ERROR_SUCCESS As Long = 0

Public Function DownloadFile(ByVal SourceURL As String, ByVal FileName As String) As Boolean
DoEvents
DownloadFile = URLDownloadToFile(0&, SourceURL, FileName, BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS
End Function

liujinhuagirl 2004-10-26
  • 打赏
  • 举报
回复
to xxlroad(土八路)
给我什莫东西呀!我们公司只让用msn:stargirl294@hotmail.com!谢谢你的帮助!
xxlroad 2004-10-26
  • 打赏
  • 举报
回复
随便给的分,大家不要介意。

谢谢大家的帮助!

4年前常来的。现在工作忙了基本没有什么来了。
xxlroad 2004-10-25
  • 打赏
  • 举报
回复
to: elongnet618 (飞翔)

怎么给你,麻烦你说下。
liujinhuagirl 2004-10-25
  • 打赏
  • 举报
回复
关注之中!
行云边 2004-10-22
  • 打赏
  • 举报
回复
如果你的MSDN是2003 的话 参考 这个文章 里面还有例子:
Win32 Internet HTTP Functions in Visual Basic
行云边 2004-10-22
  • 打赏
  • 举报
回复
可以参考 标题为 《Visual Basic and the Win32 Internet SDK》 的 MSDN里的一篇文章
行云边 2004-10-22
  • 打赏
  • 举报
回复
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, sBuffer As Byte, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByVal sBuffer As Any, ByRef lBufferLength As Long, ByRef lIndex As Long) As Integer


Public Function ReadUrl(ByVal sUrl As String, Optional vFileName As _
Variant) As Boolean
Dim sReadBuffer As String * 2048 ' Bytes to read from one call
Dim lNumberOfBytesRead As Long ' Bytes read from call to InternetReadFile
Dim lTotalBytesRead As Long ' Total bytes read
Dim bDoLoop As Boolean ' Return value from InternetReadFile
Dim bReadInternetFile As Boolean
Dim bWriteToFile As Boolean
On Error GoTo errReadUrl
Screen.MousePointer = vbHourglass
SetStatus "Opening Url..."
If Not IsMissing(vFileName) Then
Dim iFileNum As Integer
iFileNum = FreeFile
Open CStr(vFileName) For Binary As iFileNum
bWriteToFile = True
End If
hUrlFile = InternetOpenUrl(hInternetSession, sUrl, vbNullString, 0,_
INTERNET_FLAG_RELOAD, 0)
If CBool(hUrlFile) Then
sContents = scBlankStr
bDoLoop = True
While bDoLoop
sReadBuffer = scBlankStr
bDoLoop = InternetReadFile(hUrlFile, sReadBuffer, Len(sReadBuffer), _
lNumberOfBytesRead)
If Not CBool(bDoLoop) Then CheckError
lTotalBytesRead = lTotalBytesRead + lNumberOfBytesRead
SetStatus "Reading Url: " & CStr(lTotalBytesRead) & " Bytes read..."
If CBool(lNumberOfBytesRead) Then
If bWriteToFile Then
Put #iFileNum, , sReadBuffer
Else
sContents = sContents & Left$(sReadBuffer,lNumberOfBytesRead)
End If
Else
bDoLoop = False
bReadInternetFile = True
End If
Wend
InternetCloseHandle (hUrlFile)
ReadUrl = True
Else
CheckError
End If
If bWriteToFile Then Close
SetStatus "Ready"
Screen.MousePointer = vbDefault
Exit Function
errReadUrl:
sLastError = Error$(Err)
Screen.MousePointer = vbDefault
Exit Function
End Function

jeffzhu 2004-10-22
  • 打赏
  • 举报
回复
晕哦,前面的贴子里不是有人给回了吗,vb有好多种组件可用来获取url信息.

先引用Microsoft Internet Transfer Control (<ctrl> + <t>)
从工具栏拖一个Inet到窗体上名称为Inet1,然后下面的代码就可以了.

Dim urlContent As String
urlContent = Inet1.OpenURL("www.flashman.com.cn")
Debug.Print urlContent

至于怎么处理获取的信息就是别的事情了.


Reker熊 2004-10-22
  • 打赏
  • 举报
回复
Winsock(下载网页或文件)
http://blog.csdn.net/tdl982324/archive/2004/09/29/120602.aspx
newsjb 2004-10-22
  • 打赏
  • 举报
回复
up
beijingkuandai 2004-10-22
  • 打赏
  • 举报
回复
同意楼上的inetl
WebBroswer控件应该也可以
_l_ 2004-10-22
  • 打赏
  • 举报
回复
你搜索下我写的网络卡车


好几年前写的工具了
jam021 2004-10-22
  • 打赏
  • 举报
回复
关注,帮你顶!
fxyfx 2004-10-22
  • 打赏
  • 举报
回复
up
fhvsbgmy 2004-10-22
  • 打赏
  • 举报
回复
对呀!inetl不是就可以实现了吗?
还要什么功能?
starsoulxp 2004-10-21
  • 打赏
  • 举报
回复
关注

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧