• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 11 رای - 2 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: سورس کد خواندن محتویات وب پیج (ویژوال بیسیک 6)
حالت موضوعی
#1
Read an internet web page with API calls

کد:
Read an internet web page with API calls

The following routine uses API calls to read/download an internet file. A routine demonstrating how to use this code can be found at the bottom of this post.

Option Explicit
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" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, 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


'Purpose     :  Retreview text from a web site
'Inputs      :  sURL                The URL and file name to extract the text from
'               [lBufferSize]       The number of characters to extract.
'                                   If value is -1 the reads the whole page.
'Outputs     :  The text found on the web site
'Notes       :  NOT SUITABLE FOR ACCESSING THE INTERNET THROUGH A ....... SERVER


Function InternetGetText(sURL As String, Optional lBufferSize As Long = -1) As String
    Dim lhOpen As Long, lhFile As Long, sBuffer As String, lRet As Long
    Const clBufferIncrement As Long = 2000
    Const scUserAgent = "VBUsers"
    Const INTERNET_OPEN_TYPE_PRECONFIG = 0, INTERNET_FLAG_EXISTING_CONNECT = &H20000000
    Const INTERNET_OPEN_TYPE_DIRECT = 1, INTERNET_OPEN_TYPE_PROXY = 3
    Const INTERNET_FLAG_RELOAD = &H80000000
    
    If lBufferSize = -1 Then
        'Create an arbitary buffer to read the whole file in parts
        sBuffer = String$(clBufferIncrement, Chr$(0))
    Else
        'Create a specified buffer size
        sBuffer = String$(lBufferSize, Chr$(0))
    End If
    'Create an internet connection
    lhOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    'Open the url
    lhFile = InternetOpenUrl(lhOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    If lhFile = 0 Then
        'Try using p
        InternetCloseHandle lhFile
        InternetCloseHandle lhOpen
        'Create an internet connection
        lhOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
        'Open the url
        lhFile = InternetOpenUrl(lhOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_EXISTING_CONNECT, ByVal 0&)
    End If
    If lBufferSize = -1 And lhFile <> 0 Then
        'Read the whole page
        Do
            InternetReadFile lhFile, sBuffer, clBufferIncrement, lRet
            InternetGetText = InternetGetText & Left$(sBuffer, lRet)
        Loop While lRet = clBufferIncrement
    Else
        'Read the specified number of bytes from the file
        InternetReadFile lhFile, sBuffer, lBufferSize, lRet
        InternetGetText = InternetGetText & Left$(sBuffer, lRet)
    End If
    'clean up
    InternetCloseHandle lhFile
    InternetCloseHandle lhOpen
End Function

'Demonstration routine
'(Note the Debug window will only show the last 255 lines)
Sub Test()
    Dim sInterPage As String
    sInterPage = InternetGetText("http://example")
    Debug.Print sInterPage
End Sub
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
 
پاسخ
  


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  سورس کدهای ویژوال بیسیک Amin_Mansouri 8 18,466 05-15-2017، 04:35 PM
آخرین ارسال: minarad69
  سورس کد شماره گیری از مودم (ویژوال بیسیک 6 ) Amin_Mansouri 1 7,061 05-07-2017، 06:54 PM
آخرین ارسال: alikorg
  چگونه فایل exe با ویژوال بیسیک بسازیم ؟ Amin_Mansouri 4 14,632 08-13-2015، 10:08 PM
آخرین ارسال: Amin_Mansouri
  مشکل با ارور ویژوال بیسیک aghamali 4 7,997 07-03-2015، 11:14 AM
آخرین ارسال: aaaaaaaaa
  سورس کد کار با وب کم (ویژوال بسیک 6) Amin_Mansouri 1 8,572 04-20-2015، 10:10 PM
آخرین ارسال: hackert41389
  مشکل با paste بیسیک 6 aghamali 1 3,963 01-18-2015، 08:53 PM
آخرین ارسال: aghamali
  2 مشکل بیسیک 6 در ویندوز سون aghamali 3 7,856 11-07-2014، 04:25 PM
آخرین ارسال: aghamali
  سورس کد ذخیره میخوام روشنا 5 10,423 06-25-2014، 08:46 AM
آخرین ارسال: Amin_Mansouri
  دریافت سورس سایت بصورت یونیکد aleas 3 5,970 06-07-2014، 09:19 PM
آخرین ارسال: aleas
  سورس جمع آوری وبلاگ های بروز میهن بلاگ saeedh 7 10,597 05-26-2014، 04:09 PM
آخرین ارسال: Amin_Mansouri

پرش به انجمن:


Browsing: 1 مهمان