Results 1 to 2 of 2

Thread: [02/03] save image as issue

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    [02/03] save image as issue

    Using vb.net to do some screen scraping and can get to a page but when I try to save the image it doesn't turn out right. Just hoping someone can see what I must do differently:

    html page to save .gif image from:
    HTML Code:
    <img name="docImg" src="showimage.jsp?doc=123456+98765.B3Z">
    VB Code:
    1. .....
    2.  Dim baImage() As Byte
    3.  
    4.                     MyBase.URL = sURL
    5.                     MyBase.Referer = String.Empty
    6.                     baImage = MyBase.RequestBinaryData(String.Empty)
    7.  
    8.                     If (baImage Is Nothing) Then Return False
    9.  
    10.                     If MyBase.IsStatusOk Then
    11.                         MyBase.SaveDataToFile(baImage, DownloadPath)
    12.                         bReturn = True
    13.                     End If
    14. ........
    15.  
    16.     Protected Function SaveDataToFile( _
    17.       ByVal baData As Byte(), _
    18.       ByVal FilePath As String) As Boolean
    19.       Dim bReturn As Boolean
    20.  
    21.       bReturn = False
    22.  
    23.       Try
    24.         Dim os As FileStream
    25.  
    26.         os = New FileStream(FilePath, FileMode.Create)
    27.         os.Write(baData, 0, baData.Length)
    28.         os.Close()
    29.  
    30.         bReturn = True
    31.       Catch ex As Exception
    32.         ' Nothing for now
    33.       End Try
    34.  
    35.       Return bReturn
    36.         End Function
    37.  
    38. Public Function RequestBinaryData(ByVal Data As String, Optional ByVal bAutoRedirect As Boolean = False) As Byte()
    39.             Dim uriSite As Uri
    40.             Dim sReturn As String
    41.             Dim srReader As StreamReader
    42.             Dim brReader As BinaryReader
    43.             Dim bytesRead As Byte()
    44.  
    45.             sReturn = String.Empty
    46.             Try
    47.                 ' Setup request
    48.                 uriSite = New Uri(m_sURL)
    49.                 m_hwrRequest = DirectCast(WebRequest.Create(uriSite), HttpWebRequest)
    50.                 m_hwrRequest.Referer = m_sReferer
    51.                 m_hwrRequest.UserAgent = m_sUserAgent
    52.                 m_hwrRequest.AllowAutoRedirect = bAutoRedirect
    53.                 m_hwrRequest.AllowWriteStreamBuffering = True
    54.                 m_hwrRequest.KeepAlive = False
    55.                 m_hwrRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*"
    56.  
    57.                 If m_ccCookies.Count > 0 Then
    58.                     m_hwrRequest.CookieContainer = New CookieContainer()
    59.                     m_hwrRequest.CookieContainer.Add(m_ccCookies)
    60.                 End If
    61.  
    62.                 m_hwrResponse = DirectCast(m_hwrRequest.GetResponse(), HttpWebResponse)
    63.  
    64.                 bytesRead = ReadAsByteArray(m_hwrResponse.GetResponseStream())
    65.  
    66.                 If Not m_hwrResponse.Headers("Set-Cookie") Is Nothing Then
    67.                     Dim ccContainer As New CookieContainer()
    68.  
    69.                     ccContainer = New CookieContainer()
    70.                     ccContainer.SetCookies(m_hwrResponse.ResponseUri, m_hwrResponse.Headers("Set-Cookie"))
    71.                     m_ccCookies.Add(ccContainer.GetCookies(m_hwrResponse.ResponseUri))
    72.                 End If
    73.  
    74.                 Me.Referer = m_hwrResponse.ResponseUri.AbsoluteUri
    75.             Catch wex As Exception
    76.                 RaiseEvent RequestError(wex)
    77.  
    78.             Catch ex As Exception
    79.                 RaiseEvent RequestError(ex)
    80.  
    81.             End Try
    82.  
    83.             Return bytesRead
    84.         End Function

  2. #2
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: [02/03] save image as issue

    Are you making sure that when you are screen scraping that you are manually appending the domain, and folders in front of that link? You have to do that since it is a relative link, and not an absolute link... Even still, not sure how it works with jsp pages...

    As in... "http://thesite.com/foldername/showimage.jsp?doc=123456+98765.B3Z" for the full resource path...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width