Avatar billede a-frandsen Praktikant
22. januar 2013 - 11:22 Der er 1 kommentar

Hente data fra Krak til Excel

Hej
Jeg skal hente nogle data fra krak og indsætte i et excel ark, men er der ikke en nemmere metode at gøre det på?

Jeg skal have indsat søgningen over alle forsamlingshuse
http://www.krak.dk/forsamlingshuse/s%C3%B8g.cs ind med navn, adresse, postnr. og by.

Tænkte på måske noget a la:
http://www.eksperten.dk/spm/816032

Håber der er nogen der kan hjælpe

Hilsen
Anette
Avatar billede Unicco Nybegynder
19. februar 2013 - 22:41 #1
Nedenstående er blevet brugt til dgs.dk som er næsten identisk med krak.dk. Har udbygget en funktion, så den frasortere alle intetsigende resultater, som dgs.dk / krak.dk har lavet for at kunderne fremgår i oftere søgerelationer. Har selv brugt nedenstående i forbindelse med et faktueringssystem, hvor nye debitorer nemt kan søges direkte igennem applikationen.

Nedenstående skal placeres i et module, og du skal blot lave en standard procedure som deklarer strSearchName (dit ønskede søgemål)

Sub NavigateTo118(ByVal strSearchName As String)
' Go the the correct site, and open display InternetExplorer.
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Dim strData As String              '1. Declare a string (strData), which collects all HTML-related elements from the page.
    Dim varDataArray As Variant        '2. Declare a array as variant. Using a Split function, which returns a zero-based one-dimensional array.
    Dim intArrayCount As Integer        '3. Declare a countingfuntion as integer. Looping through all innerHTML-data.
   
    Dim strResultDebitor As String      'Split data into a string, so the data is easy to use.
    Dim strResultPhone As String        'Split data into a string, so the data is easy to use.
    Dim strResultAdress As String      'Split data into a string, so the data is easy to use.
    Dim strResultArea As String        'Split data into a string, so the data is easy to use.
    Dim strResultCity As String        'Split data into a string, so the data is easy to use.
    Dim strResultAreaCode As String    'Split data into a string, so the data is easy to use.
   
    Dim intCArrPhoneNum As Integer      'The phonenumber is placed in various locations. Use a loop to find the right placement.
    Dim intCResults As Integer          'Declare a counterfunction (integer) to sumerious the number of collections.
    Dim intLenResultCity As Integer    'The areacode and city is associated, which means we have to seperate them.
   
    intCResults = 1
    intCResultsPosition = 0
    frm_T1_Kundeoplysninger.lstSearchDebitor.Clear

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Call ProcessBar(frm_T1_Kundeoplysninger, strStep:="Forbinder til http://dgs.dk...", intStep:=1, intStepTotal:=3)

    Set ieApp = New InternetExplorer 'Starting InternetExplorer.
    ieApp.Visible = False 'Assign True if u want to see InternetExplorer work. False will hide InternetExplorer
    ieApp.Navigate "http://degulesider.dk/" & strSearchName & "/søg.cs" 'Declare your navigation.

    Do While ieApp.Busy: DoEvents: Loop 'Await untill site is fully loaded.
    Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop 'Await untill site is fully loaded.
    Set ieDoc = ieApp.document 'Assign page.

    Call ProcessBar(frm_T1_Kundeoplysninger, strStep:="Søger efter debitorer...", intStep:=2, intStepTotal:=3)
   
Retry:

    On Error GoTo Retry
   
    strData = ieDoc.body.innerText
   
    If strData <> vbNullString Then
       
        varDataArray = Split(strData, vbCrLf) 'Split Data into separate lines, and declare each line into a array.
   
        If UBound(varDataArray) < 80 Then GoTo Retry
       
        For intArrayCount = 0 To UBound(varDataArray)
            If intCResults < 9 Then
                If InStr(1, varDataArray(intArrayCount), intCResults & ". ") > 0 Then
                    If InStr(1, UCase(varDataArray(intArrayCount + 1)), UCase(strSearchName)) > 0 Then
                        For intCArrPhoneNum = 1 To 8
                            If Len(varDataArray(intArrayCount + 1 + intCArrPhoneNum)) = 12 Then
                                intCResults = intCResults + 1
                                intCResultsPosition = intCResultsPosition + 1
                                strResultDebitor = varDataArray(intArrayCount + 1)
                                strResultPhone = varDataArray(intArrayCount + 1 + intCArrPhoneNum)
                                strResultAdress = varDataArray(intArrayCount + 2 + intCArrPhoneNum)
                                If varDataArray(intArrayCount + 3 + intCArrPhoneNum) = vbNullString Then
                                    intLenResultCity = Len(varDataArray(intArrayCount + 4 + intCArrPhoneNum))
                                    strResultAreaCode = Left(varDataArray(intArrayCount + 4 + intCArrPhoneNum), 4)
                                    strResultCity = Right(varDataArray(intArrayCount + 4 + intCArrPhoneNum), intLenResultCity - 5)
                                Else
                                    intLenResultCity = Len(varDataArray(intArrayCount + 3 + intCArrPhoneNum))
                                    strResultAreaCode = Left(varDataArray(intArrayCount + 3 + intCArrPhoneNum), 4)
                                    strResultCity = Right(varDataArray(intArrayCount + 3 + intCArrPhoneNum), intLenResultCity - 5)
                                End If
                                Call DebitorResults(strResultDebitor, strResultAdress, strResultAreaCode, strResultCity, strResultPhone)
                                Exit For
                            End If
                        Next intCArrPhoneNum
                    Else
                        If intCResults = 1 Then
                            If InStr(1, UCase(varDataArray(intArrayCount + 1)), UCase(strSearchName)) = 0 Then
                                For intCArrPhoneNum = 1 To 8
                                    If Len(varDataArray(intArrayCount + 1 + intCArrPhoneNum)) = 12 Then
                                        intCResults = intCResults + 1
                                        intCResultsPosition = intCResultsPosition + 1
                                        strResultDebitor = varDataArray(intArrayCount + 1)
                                        strResultPhone = varDataArray(intArrayCount + 1 + intCArrPhoneNum)
                                        strResultAdress = varDataArray(intArrayCount + 2 + intCArrPhoneNum)
                                        If varDataArray(intArrayCount + 3 + intCArrPhoneNum) = vbNullString Then
                                            intLenResultCity = Len(varDataArray(intArrayCount + 4 + intCArrPhoneNum))
                                            strResultAreaCode = Left(varDataArray(intArrayCount + 4 + intCArrPhoneNum), 4)
                                            strResultCity = Right(varDataArray(intArrayCount + 4 + intCArrPhoneNum), intLenResultCity - 5)
                                        Else
                                            intLenResultCity = Len(varDataArray(intArrayCount + 3 + intCArrPhoneNum))
                                            strResultAreaCode = Left(varDataArray(intArrayCount + 3 + intCArrPhoneNum), 4)
                                            strResultCity = Right(varDataArray(intArrayCount + 3 + intCArrPhoneNum), intLenResultCity - 5)
                                        End If
                                        Call DebitorResults(strResultDebitor, strResultAdress, strResultAreaCode, strResultCity, strResultPhone)
                                        Exit For
                                    End If
                                Next intCArrPhoneNum
                            End If
                        End If
                    End If
                End If
            Else
                Exit For
            End If
        Next intArrayCount
               
        ieApp.Quit 'Close IE
       
        If intCResultsPosition = 0 Then
            Call ProcessBar(frm_T1_Kundeoplysninger, strStep:="Fandt desværre ingen resultater" & intCResultsPosition, intStep:=3, intStepTotal:=3)
        ElseIf intCResultsPosition >= 1 Then
            Call ProcessBar(frm_T1_Kundeoplysninger, strStep:="Antal søgeresultater: " & intCResultsPosition, intStep:=3, intStepTotal:=3)
        End If
       
    Else
        Exit Sub
    End If
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester