All pastes #834391 Raw Edit

Mine

public text v1 · immutable
#834391 ·published 2007-12-28 04:28 UTC
rendered paste body
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Text.RegularExpressions
Imports System
Imports System.Xml


<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service

    Inherits System.Web.Services.WebService
    '    <WebMethod()> _
    '    Public Function HelloWorld() As String
    '        Return "Hello World"
    '    End Function

    <WebMethod()> _
    Public Function Crawl() As String
        Dim url As String
        Dim cokro = New HTMLPage()
        Dim output As String
        Dim disallow_list As New ArrayList()
        Dim allow_list As New ArrayList()
        Dim page_num As Integer
        Dim lanjut, next_page As Boolean
        Dim i, j As Integer
        Dim txt As String
        Dim sFileName As String
        sFileName = "c:\xmltest.xml"
        Dim s2 As FileStream
        Dim mode As Integer

        If Not File.Exists(sFileName) Then
            s2 = File.Create(sFileName)
            mode = 0
        Else
            s2 = File.Open(sFileName, FileMode.Append, FileAccess.Write, FileShare.Read)
            'Try
            's2.Seek(-8, SeekOrigin.Begin)
            'Finally
            'End Try
            's2.Position = 10
            mode = 1
        End If
        If mode = 1 Then
            'MsgBox(s2.Position)
            's2.Position = s2.Position - 30
            MsgBox(SeekOrigin.End)
            s2.Seek(0, SeekOrigin.Begin)
        End If
        Dim myxml As New XmlTextWriter(s2, Nothing)

        disallow_list.Add("http://www.mypropertyforsale.co.uk/index.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/buying.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/selling.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/europeanproperties.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/guides.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/resources.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/portfolio.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/user_login.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/guides_selling.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/sell_testimonials.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/contact.php")
        disallow_list.Add("http://www.mypropertyforsale.co.uk/affiliate.php")
        disallow_list.Add("http://www.brit-net.com")
        Dim oregex As Regex = New Regex("([jJ][aA][vV][aA][sS][cC][rR][iI][pP][tT])|([?])|([hH][oO][uU][sS][eE][sS][iI][nN])", RegexOptions.IgnoreCase Or RegexOptions.Compiled)
        url = "http://www.mypropertyforsale.co.uk"
        If cokro.LoadSource(url) Then
            Dim strHRefs() As String = cokro.GetHRefs()
            If Not strHRefs Is Nothing Then
                If strHRefs.Length <> 0 Then
                    For i = 0 To strHRefs.Length - 1
                        If (Not oregex.IsMatch(strHRefs(i))) And (disallow_list.IndexOf(strHRefs(i)) = -1) And (allow_list.IndexOf(strHRefs(i)) = -1) Then
                            output = output + strHRefs(i) + "<br>"
                            allow_list.Add(strHRefs(i))
                        End If
                    Next
                End If
            End If
        End If
        myxml.WriteStartElement("Fetch")
        Dim a, b As Integer
        For j = 0 To allow_list.Count - 1
            If cokro.LoadSource(allow_list.Item(j)) Then
                txt = cokro.Text
                Dim lokasi, kondisi, tipe, ktidur, kmandi, harga, MPFS As String
                a = txt.IndexOf("Location")
                b = txt.IndexOf("Condition")
                lokasi = txt.Substring(a + 10, b - (a + 10) - 1)
                a = txt.IndexOf("Condition")
                b = txt.IndexOf("Type of property")
                kondisi = txt.Substring((a + 11), b - (a + 11) - 1)
                a = txt.IndexOf("Type of property")
                b = txt.IndexOf("No. of Bedrooms")
                tipe = txt.Substring((a + 18), b - (a + 18) - 1)
                a = txt.IndexOf("No. of Bedrooms")
                b = txt.IndexOf("No. of Reception rooms")
                ktidur = txt.Substring((a + 17), b - (a + 17) - 1)
                a = txt.IndexOf("No. of Bathrooms/WC's")
                b = txt.LastIndexOf("Price")
                kmandi = txt.Substring((a + 23), b - (a + 23) - 1)
                a = txt.LastIndexOf("Price")
                b = txt.IndexOf("MPFS code")
                harga = txt.Substring((a + 7), b - (a + 7) - 1)
                a = txt.IndexOf("MPFS code")
                b = txt.IndexOf("PRINT")
                MPFS = txt.Substring((a + 11), b - (a + 11) - 1)

                myxml.WriteStartElement("idrumah")
                myxml.WriteElementString("tanggal", CStr(Now))
                myxml.WriteElementString("nomer_id", MPFS)
                myxml.WriteElementString("lokasi", lokasi)
                myxml.WriteElementString("tipe", tipe)
                myxml.WriteElementString("ktidur", ktidur)
                myxml.WriteElementString("kmandi", kmandi)
                myxml.WriteElementString("harga", harga)
                'myxml.WriteWhitespace("\n")
                myxml.WriteEndElement()
            End If
        Next
        myxml.WriteEndElement()
        myxml.Close()
        s2.Close()


        Return output
    End Function
End Class