Convert VB console code into VB.Net Web Application?

Anybody know how to convert this into a project and have a webform work with it instead of the console?

http://sourceforge.net/projects/imdbparse/

' Copyright (c) 2004, Andrew Brereton
' All rights reserved.
'
' Redistribution and use in source and binary forms, with or without
' modification, are permitted provided that the following conditions are met:
'  * Redistributions of source code must retain the above copyright notice, this
'    list of conditions and the following disclaimer.
'  * Redistributions in binary form must reproduce the above copyright notice,
'    this list of conditions and the following disclaimer in the documentation
'    and/or other materials provided with the distribution.
'  * Neither the name of the original developer nor the names of its contributors
'    may be used to endorse or promote products derived from this software
'    without specific prior written permission.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
' ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
' ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
' ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Option Explicit On

Imports System
Imports System.IO
Imports System.Net
Imports System.Text.RegularExpressions

Module IMDBParse

  Private html As String

  Sub Main()

    Dim req As System.Net.HttpWebRequest
    Dim res As System.Net.HttpWebResponse
    Dim sr As System.IO.StreamReader
    Dim html As String
    Dim cmd As String = Command()
    Dim i As Integer
    Dim intStart As Integer, intEnd As Integer, intLength As Integer, intExtraSpace As Integer
    Dim strStart As String, strEnd As String, intStartLen As Integer, intEndLen As Integer, strTemp As String
    Dim strTitle As String, strYear As String, strDirector As String, strGenre As String, strTagline As String, strRunningTime As String, strAudience As String, strPlot As String

    If ValidCommand(cmd) Then

      req = System.Net.WebRequest.Create("http://imdb.com/title/tt" & cmd & "/")
      req.Accept = "text/html, application/xml;q=0.9, application/xhtml+xml;q=0.9, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1"
      req.UserAgent = "Opera/7.23 (Windows NT 5.0; U)  [en]"
      req.Headers.Add("Accept-Charset", "windows-1252, utf-8, utf-16, iso-8859-1;q=0.6, *;q=0.1")
      req.Headers.Add("Accept-Encoding", "deflate, gzip, x-gzip, identity, *;q=0")
      req.Headers.Add("Accept-Language", "en")
      req.Headers.Add("Accept-Encoding", "gzip,deflate")
      res = req.GetResponse()

      'read in the page 
      sr = New StreamReader(res.GetResponseStream())

      html = sr.ReadToEnd()

      sr.Close()

      intStart = 1

      ' *** TITLE***
      intExtraSpace = 0
      strStart = "<title>" : intStartLen = Len(strStart)
      strEnd = "</title>" : intEndLen = Len(strEnd)
      intStart = InStr(intStart, html, strStart, 1) + intStartLen + intExtraSpace
      intEnd = InStr(intStart + intStartLen - intExtraSpace, html, strEnd, 1)
      intLength = intEnd - intStart
      strTemp = Mid(html, intStart, intLength)
      strTitle = Left(strTemp, InStrRev(strTemp, " ") - 1) ' Find the space jsut before the "(yyyy)" in the title
      strTitle = StripBlanks(strTitle)
      Console.WriteLine(strTitle)

      ' *** YEAR ***
      strYear = Mid(strTemp, InStrRev(strTemp, "(") + 1, 4)
      Console.WriteLine(strYear)

      ' *** DIRECTOR ***
      intExtraSpace = 12
      strStart = "/name/" : intStartLen = Len(strStart)
      strEnd = "</a>" : intEndLen = Len(strEnd)
      intStart = InStr(intStart, html, strStart, 1) + intStartLen + intExtraSpace
      intEnd = InStr(intStart + intStartLen - intExtraSpace, html, strEnd, 1)
      intLength = intEnd - intStart
      strDirector = Mid(html, intStart, intLength)
      strDirector = StripBlanks(strDirector)
      Console.WriteLine(strDirector)

      ' *** GENRE(s) ***
      intExtraSpace = 1
      strStart = "Genre" : intStartLen = Len(strStart)
      strEnd = "(more)" : intEndLen = Len(strEnd)
      intStart = InStr(intStart, html, strStart, 1) + intStartLen + intExtraSpace
      intEnd = InStr(intStart + intStartLen - intExtraSpace, html, strEnd, 1)
      intLength = intEnd - intStart
      strGenre = Mid(html, intStart, intLength)
      strGenre = StripHTML(strGenre)
      Console.WriteLine(strGenre)

      ' *** TAGLINE ***
      intExtraSpace = 6
      strStart = "Tagline" : intStartLen = Len(strStart)
      strEnd = "<a" : intEndLen = Len(strEnd)
      intStart = InStr(intStart, html, strStart, 1) + intStartLen + intExtraSpace
      intEnd = InStr(intStart + intStartLen - intExtraSpace, html, strEnd, 1)
      intLength = intEnd - intStart
      strTagline = Mid(html, intStart, intLength)
      strTagline = StripBlanks(strTagline)
      Console.WriteLine(strTagline)

      ' *** PLOT ***
      intExtraSpace = 6
      strStart = "Plot Outline" : intStartLen = Len(strStart)
      strEnd = "<a" : intEndLen = Len(strEnd)
      intStart = InStr(intStart, html, strStart, 1) + intStartLen + intExtraSpace
      intEnd = InStr(intStart + intStartLen - intExtraSpace, html, strEnd, 1)
      intLength = intEnd - intStart
      strPlot = Mid(html, intStart, intLength)
      strPlot = StripBlanks(strPlot)
      Console.WriteLine(strPlot)

      ' *** RUNNING TIME ***
      intExtraSpace = 6
      strStart = "Runtime" : intStartLen = Len(strStart)
      strEnd = "min" : intEndLen = Len(strEnd)
      intStart = InStr(intStart, html, strStart, 1) + intStartLen + intExtraSpace
      intEnd = InStr(intStart + intStartLen - intExtraSpace, html, strEnd, 1)
      intLength = intEnd - intStart
      strRunningTime = Mid(html, intStart, intLength)
      strRunningTime = StripBlanks(strRunningTime)
      Console.WriteLine(strRunningTime)

      ' *** AUDIENCE ***
      intExtraSpace = 0
      strStart = ">Australia:" : intStartLen = Len(strStart)
      strEnd = "/" : intEndLen = Len(strEnd)
      intStart = InStr(intStart, html, strStart, 1) + intStartLen + intExtraSpace
      intEnd = InStr(intStart + intStartLen - intExtraSpace, html, strEnd, 1) - 17
      intLength = intEnd - intStart
      strAudience = Mid(html, intStart, intLength)
      strAudience = StripBlanks(strAudience)
      Console.WriteLine(strAudience)

      sr.Close()
      res.Close()

    End If

    End

  End Sub

  ' Strip the HTML from the given string
  Private Function StripHTML(ByVal strHTML As String) As String
    Return (Regex.Replace(strHTML, "<[^>]*>", ""))
  End Function

  ' Strip odd characters from the string
  Private Function StripBlanks(ByVal strText As String) As String
    strText = Replace(strText, vbCr, "")
    strText = Replace(strText, vbLf, "")
    strText = Trim(strText)
    Return (strText)
  End Function

  ' Validate the commandline parameter
  Private Function ValidCommand(ByVal cmd As String) As Boolean
    Return ((cmd.Length() = 7) And (IsNumeric(cmd)))
  End Function

End Module

0
jballhrb
4/27/2005 7:54:07 PM
asp.net.visual-basic.net 3721 articles. 0 followers. Follow

3 Replies
1002 Views

Similar Articles

[PageSpeed] 59

There are a number of issues with this code, as it doesn't work for quite a large number of entries in the IMDB database. I'm not going to guarantee that mine is that much better a version, and the regex code could certainly be improved.

To use it, call the InternetMovieDBParser.RetrieveRecord, passing in a string containing 7 numeric digits. This will either

(a) return you an InternetMovieDBRecord object with the fields that it knows filled in. You can then display these on a form, or

(b) throw an exception at you because something's wrong with the request, the server is down, etc.

Personally,  I wouldn't use this code on any form of production server, but if it's just for fun then no problems. I will reiterate the disclaimer from before:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Also, please don't forget to credit the original author of the code on which this is derived. If you intend to use the code, you MUST obey the terms and conditions of the copyright notice posted above.

Imports System
Imports System.IO
Imports System.Net
Imports System.Text.RegularExpressions

Public Class InternetMovieDBRecord
 
Public ReadOnly Title As String
 
Public ReadOnly Director As String
 
Public ReadOnly Year As String
 
Public ReadOnly Genre As String
 
Public ReadOnly PlotOutline As String
 
Public ReadOnly TagLine As String
 
Public ReadOnly AustralianCertificate As String
 
Public ReadOnly RunningTime As String

  Friend Sub New(ByVal title As String, ByVal director As String, ByVal year As String, ByVal genre As String, _
    ByVal plotOutline As String, ByVal tagLine As String, ByVal ausCert As String, ByVal runTime As String)
   
Me.Title = title
   
Me.Director = director
   
Me.Year = year
   
Me.Genre = genre
   
Me.PlotOutline = plotOutline
   
Me.TagLine = tagLine
   
Me.AustralianCertificate = ausCert
   
Me.RunningTime = runTime
  End Sub
End
Class

Public Class InternetMovieDBParser
 
Public Shared Function RetrieveRecord(ByVal cmd As String) As InternetMovieDBRecord
 
Dim req As System.Net.HttpWebRequest
 
Dim res As System.Net.HttpWebResponse
 
Dim sr As System.IO.StreamReader
 
Dim html As String
 
Dim m As Match
 
Dim title As String
 
Dim year As String
 
Dim director As String
 
Dim genre As String
 
Dim tagLine As String
 
Dim plotOutline As String
 
Dim ausCert As String
 
Dim runTime As String

  Try
   
req = CType(System.Net.WebRequest.Create("http://imdb.com/title/tt" & cmd & "/"), HttpWebRequest)
   
res = CType(req.GetResponse(), HttpWebResponse)
   
'read in the page
   
sr = New StreamReader(res.GetResponseStream())
   
html = sr.ReadToEnd()
   
html = Regex.Replace(html, "&nbsp;", "")
   
m = Regex.Match(html, "<title>(.*) \((\d{4})\)</title>")
   
title = m.Groups(1).Value
    year = m.Groups(2).Value

    m = Regex.Match(html, "/name/nm\d{7}/"">(.*)</a>")
   
director = StripHTML(Regex.Replace(m.Groups(1).Value, "\(more\)", ""), " / ").TrimEnd(New Char() {"/"c, " "c})

    m = Regex.Match(html, "Genre:</b>\n(.*)(\(more\)|\n)")
   
genre = StripHTML(Regex.Replace(m.Groups(1).Value, "\(more\)", ""), "")

    m = Regex.Match(html, "Tagline:</b> ?(.*)(( <a)|\n)")
   
tagLine = Regex.Replace(m.Groups(1).Value, "\(more\)", "")

    m = Regex.Match(html, "Plot (?:(?:Outline)|(?:Summary)):</b> ?([^<]*)(( <a)|\n)")
   
plotOutline = Regex.Replace(m.Groups(1).Value, "\(more\)", "")

    m = Regex.Match(html, "Runtime:</b>\n(\d*) min")
   
runTime = m.Groups(1).Value

    m = Regex.Match(html, ">Australia:(.)<")
   
ausCert = m.Groups(1).Value

    Return New InternetMovieDBRecord(title, director, year, genre, plotOutline, tagLine, ausCert, runTime)

    Finally
     
If Not sr Is Nothing Then sr.Close()
     
If Not res Is Nothing Then res.Close()
    End Try
 
End Function

  ' Strip the HTML from the given string
  Private Shared Function StripHTML(ByVal strHTML As String, ByVal replace As String) As String
   
Return (Regex.Replace(strHTML, "(<[^>]*>)+", replace))
 
End Function
End
Class


Regards

Dave
0
DMW
4/28/2005 10:21:56 AM

I do believe that Amazon provides access to IMDB through their webservices API.

0
JeffreyABecker
4/28/2005 12:00:32 PM

It's just for fun. I have another IMDB program from sourceforge that it java based, and I can't seem to get it to do what I want. I saw this while looking around and thought it was interesting. I am using a web application to access the Access Database that my movies go into.

I tried using the Amazon webservices API, but havn't gotten far on that yet.

Thanks.

0
jballhrb
4/28/2005 1:15:52 PM
Reply:

Similar Artilces:

What are the diff. visual basic 6 and vb.net ? How to convert the VB6 project to vb.net proj ?
What are the diff. visual basic 6 and vb.net ? How to convert the VB6 project to vb.net proj ? with code and interface too. There are entire forums dedicated to the differences between the two, and to convert your projects you should try the upgrade wizard in Visual Studio....

Converting Web Site from Vb.Net 2003 to Vb.Net 2005
I have a web site in vb.net 2003 that I what to convert to vb.net 2005. I open my web site in the visual studio 2005 by Local IIS option. I follow the steps of the visual studio conversion wizard.In the conversion report I received the following warning 'Referencepath' settings have not been converted.  Can anyone tell what I have to do to make this warning disappear? Best regards,Sérgio 'Referencepath'  is a property you can set with with VS2003 project file, sothat when ever you to do Add reference this path is serached for class libraries.  We do not  have that ...

How to convert C#.Net code to VB.Net code ???...
HI, i was searching something new, then i suddenly find some tips to convert C#.Net code to VB.Net but i did not do well. i am puttint its url here plz tell me how to convert C#.Net code to VB.Net. http://www.dotnetspider.com/code/C-273-Convert-C-VB-NET.aspx Jasim...Please remember to click “Mark as Answer” on the post that helps youJasim AkhtarNew Delhi ( INDIA ) It would be better if you write the problem you having, while converting from C# to VB.NET. You cannot completely rely on online converters. ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Bl...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

Convert VB.Net application to C#.net
Haican any one help me to convert VB.Net application in this link to C#.net http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6718&lngWId=10RegardsAnu Palavila  Regards Anu Palavila Use this Free Conversion tool - http://www.developerfusion.com/tools/convert/vb-to-csharp/  ASP.NET Grid With Excel Capabilities | 27 GridView Tips & Tricks | Hosting your site? | SQL Server Tips Other Code Convertors (convert VB to C# and C# to VB) http://converter.telerik.com/ http://www.developerfusion.com/tools/convert/csharp-to-vb/ http://www.dotnetspider.com...

converting vb.net 2003 files to vb.net 2005
Hi, i am beginner..i watch videos about vb.net..they made on vs.net 2003 when i wrote these codes in 2005 ,it gives errors..is there any program which convert the code automatically?   thanks,Thanks,Speranza What videos are you talking about?  There are lots of great, up-to-date ASP.NET Videos on this site for free.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! i am talking about learnvisualstudio.net videos..Thanks,Speranza Speranza:they made on vs.net 2003 when i wrote these codes in 2005 ,it gives errors..is there a...

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

convert code from VB to VB.Net
hi, I have both an offline application (done with Visual Basic 6.0 ) and an online application (thru ASP.Net 2.0 and Visual Basic as code behind). Right now, I have a code in Visual Basic for encrypting a file. This is working in my offline application. However, when I used the code in my online application, it got some errors in it. Maybe incompatibility with the language used. Is there any way I can convert my VB code to VB.Net? Thanks a lot. Sheila   Rock on!!! Get the VB6 code advisor from http://msdn2.microsoft.com/en-gb/vbasic/ms789135.aspx and check you existing...

How could i convert this code vb in vb.net?
Dim Report As CRAXDRT.ReportDim ReportSub As CRAXDRT.ReportDim ReportSub1 As CRAXDRT.Report Dim m_crwDatabase As CRAXDRT.Database Dim MaxDetail As IntegerDim MaxMain As Integer Dim PageCountMax As Integer Private Sub Command1_Click()     PayableVoucher "应付款挂帐单", "应付组"        End Sub Private Sub Command2_Click()     Command1.Visible = True    CRViewer1.Visible = False    Command2.Visible = False    Command3.Visible = True    Me.WindowState = 0     ...

how to convert vb.net website to csharp.net web site
Can we convert a website(VB.NET) to csharp.net website in VS2005???mahmood Why do you want to convert VB into C#? you can create new modules for the site in C#, and they can co-exist in the same system. If you have some specific requirements, then use online tools to convert vb.net into c# to convert the codebehind files. Most probably the .aspx file will remain unchanged, but you might need to make some changes here and there.You will get lots of converters online by just googling it. I would strongly recommend avoiding converting codes, as I have faced the horrors of the process. Pr...

Is there a software to convert VB codes to VB.net codes automatically?
hi there! Do anyone of you know if there is any software to convert VB codes to VB.net codes? Or must i maunally convert them? Visual Studio.NET 2000 and 2003 versions automatically convert VB 6 code to VB.NET code, for the most part. Refer to Preparing Your Visual Basic 6.0 Applications for the Upgrade to Visual Basic .NET for more information. Hope this helps, AppanASP.NET Team This posting is provided "AS IS" with no warranties, and confers no rights. thanks! =) Is this case same for Visual C codes? Same concept. Refer to Managed Extensions for C++ Migratio...

Converting windows application using web service from Visual C#.net 2003 to Visual Studio.net 2005
Hello, everyone! I have a solution which contains a windows project,a web service project and several other library projects. These projects were coded under visual c#.net 2003. Now I need to converted them to use Visual Studo.net 2005. Does any one know any article providing step-by-step guide  to converting WINDOWS APPLICATION with web service? I can find one under MSDN for converting web project.  But I guess I am a little confused if mine should follow this article since I am using web service in my windows application? Thanks a lot in advance.  ...

Web resources about - Convert VB console code into VB.Net Web Application? - asp.net.visual-basic.net

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Second visa application 'likely' to be approved
The family of a terminally ill Pakistani student can 'hopefully come to Australia sooner rather than later' says Immigration Minister Peter Dutton. ...

Tashfeen Malik's visa application under scrutiny - Business Insider Deutschland
The US government has released the visa application for Tashfeen Malik, who along with her husband killed 14 people in an attack in San Bernardino, ...

Panasonic Develops a Stretchable Resin Film and Its Application Materials for Stretchable Electronics ...
A stretchable film is developed. This film stretches to 2.5 times the original length and then returns to the original form. A conductive paste ...

MBA: Mortgage Applications Increase in Latest MBA Weekly Survey, Purchase Applications up 37% YoY
From the MBA: Refinance, Purchase Applications Both Up in Latest MBA Weekly Survey Mortgage applications increased 7.3 percent from one week ...

Cal State Schools Get Record Number Of Applications For 2016 Term
Schools in the California State University system received a record number of applications for the upcoming 2016 fall term, with more than 830,000 ...

German-Based Spirea Promotes Decentralized PV Applications In Uruguay
... Its technical operations specialist, Laurie Lawrence, pointed out that Uruguay [&hellip German-Based Spirea Promotes Decentralized PV Applications ...

Visa application of San Bernardino shooter released
CNN Visa application of San Bernardino shooter released CNN (CNN) The visa application of one of the San Bernardino shooters was released ...

Panasonic touch panel production to be solely for vehicle applications by 2020, says report
Panasonic is aiming to transfer its touch panel production completely to vehicle applications by 2020 in order to meet increasing demand for ...

Pre-K Applications Begin Jan 25, a Month Earlier Than Last Year, City Says
The DOE has moved the process up to Jan. 25 on the heels of a similar schedule shift for kindergarten. MANHATTAN — The application period for ...

Resources last updated: 1/1/2016 10:37:46 AM