UrlCombine()

Hallo,
kann mir jemand die verwendug von UrlCombine erklären sub oder fnk.

declariere sie so

Private Declare Sub UrlCombine Lib „shlwapi.dll“ Alias „UrlCombineA“ _
(ByVal pszBase As String, ByVal pszRelative As String)

und rufe sie so auf
gefundene_url = UrlCombine(url, href_attr)

nur läuft es so nicht und die msdn lib. hilft mir in dem fall auch nicht weiter und beispile im netz sind auch sehr mager.

inne

Hallo Inne,

ich habe mal geschaut und gesehen das der Aufruf sowie die Declaration ein wenig falsch ist. Der Richtige Syntax lautet

Declare Sub UrlCombine Lib "shlwapi.dll" \_
 Alias "UrlCombineA" ( \_
 ByVal pszBase As String, \_
 ByVal pszRelative As String, \_
 ByVal pszCombined As String, \_
 ByRef pcchCombined As Long, \_
 ByVal dwFlags As Long)

Danach noch der Auszug aus der MSN
Hier siehst du auch den Aufruf der Sub :smile:
Was verstehst du denn daran nicht oder was geht nicht?

UrlCombine Function

When provided with a relative URL and its base, returns a URL in canonical form.

Syntax

HRESULT UrlCombine( 
 LPCTSTR pszBase,
 LPCTSTR pszRelative,
 LPTSTR pszCombined,
 LPDWORD pcchCombined,
 DWORD dwFlags
);

Parameters

 pszBase
 [in] Null-terminated string of maximum length INTERNET\_MAX\_URL\_LENGTH that contains the base URL.
 pszRelative
 [in] Null-terminated string of maximum length INTERNET\_MAX\_URL\_LENGTH that contains the relative URL.
 pszCombined
 [out] Pointer to a buffer to receive a null-terminated string containing the combined URL.
 pcchCombined
 [in, out] Pointer to a value set to the number of characters in the pszCombined buffer. When the function returns, the value depends on whether the function is successful or returns E\_POINTER. For other return values, the value of this parameter is meaningless.
 dwFlags
 [in] Flags that specify how the URL is converted to canonical form. The following flags can be combined.

 URL\_DONT\_SIMPLIFY
 Treat '/./' and '/../' in a URL string as literal characters, not as shorthand for navigation. See Remarks for further discussion.
 URL\_ESCAPE\_PERCENT
 Convert any occurrence of '%' to its escape sequence.
 URL\_ESCAPE\_SPACES\_ONLY
 Replace only spaces with escape sequences. This flag takes precedence over URL\_ESCAPE\_UNSAFE, but does not apply to opaque URLs.
 URL\_ESCAPE\_UNSAFE
 Replace unsafe characters with their escape sequences. Unsafe characters are those characters that may be altered during transport across the Internet, and include the (, ", #, {, }, |, \, ^, ~, [,], and ') characters. This flag applies to all URLs, including opaque URLs.
 URL\_PLUGGABLE\_PROTOCOL
 Combine URLs with client-defined pluggable protocols, according to the World Wide Web Consortium (W3C) specification. This flag does not apply to standard protocols such as ftp, http, gopher, and so on. If this flag is set, UrlCombine does not simplify URLs, so there is no need to also set URL\_DONT\_SIMPLIFY.
 URL\_UNESCAPE
 Un-escape any escape sequences that the URLs contain, with two exceptions. The escape sequences for '?' and '#' are not un-escaped. If one of the URL\_ESCAPE\_XXX flags is also set, the two URLs are first un-escaped, then combined, then escaped.

Return Value

 S\_OK pszCombined points to a string containing the combined URLs. The value of pcchCombined is set to the number of characters in the string, not counting the terminating NULL character.
 E\_POINTER The buffer was too small. The value of pcchCombined is set to the minimum number of characters that the buffer must be able to contain, including the terminating NULL character.
 Other errors A standard OLE error value is returned.

Remarks

 Items between slashes are treated as hierarchical identifiers; the last item specifies the document itself. You must enter a slash (/) after the document name to append more items; otherwise, UrlCombine exchanges one document for another. For example:

hRetVal = UrlCombine(TEXT("http://xyz/test/abc"), 
 TEXT("bar"), 
 lpszCombined, 
 &dwLength, 0);

 The preceding code returns the URL http://xyz/test/bar. If you want the combined URL to be http://xyz/test/abc/bar, use the following call to UrlCombine.

hRetVal = UrlCombine(TEXT("http://xyz/test/abc/"), 
 TEXT("bar"), 
 lpszCombined, 
 &dwLength, 0);

 If a URL string contains '/../' or '/./', UrlCombine usually treats the characters as if they indicated navigation in the URL hierarchy. The function simplifies the URLs before combining them. For instance, "/hello/cruel/../world" is simplified to "/hello/world". If the URL\_DONT\_SIMPLIFY flag is set in dwFlags, the function does not simplify URLs. In this case, "/hello/cruel/../world" is left as it stands.

Function Information

 Minimum DLL Version shlwapi.dll version 5.0 or later
 Custom Implementation No
 Header shlwapi.h
 Import library shlwapi.lib
 Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 5, Windows 98, Windows 95 with Internet Explorer 5
 Unicode Implemented as ANSI and Unicode versions.

MFG Alex

kannst du mir nicht ein beispiel geben
denn wenn es eine sub ist hat sie doch keinen rückgabe wert oder???

nun habe ich eine „Base_URL“ zb www.website.de/dir1/dir2/dir3" und auf dieser website finde ich einen link (Relative_URL) mit dem href-attr „…/…/doku1.htm“ wie benutze ich UrlCompine() um die url www.website.de/dir1.doku1.htm" zu erhalten ???

ein beispiel wäre nicht schlecht.

Private Declare Sub UrlCombine Lib „shlwapi.dll“ Alias „UrlCombineA“ _
(ByVal pszBase As String, ByVal pszRelative As String, ByVal pszCombined As String, ByRef pcchCombined As Long, ByVal dwFlags As Long)

kannst du mir nicht ein beispiel geben

Puh, da muesste ich mich nun auch mal ernsthaft dahinter klemmen, alldiweil ich das noch nie gemacht habe :-/

denn wenn es eine sub ist hat sie doch keinen rückgabe wert
oder???

Nein nur Funktionen koennen oder geben Werte zurueck. Sub’s jedoch nicht. Du kannst aber einer Sub zum Bsp. einen Wert ByRef uebergeben und ihn dann dort aendern :wink:

nun habe ich eine „Base_URL“ zb www.website.de/dir1/dir2/dir3"
und auf dieser website finde ich einen link (Relative_URL) mit
dem href-attr „…/…/doku1.htm“ wie benutze ich UrlCompine()
um die url www.website.de/dir1.doku1.htm" zu erhalten ???

Müsst ich schauen, aber warum greifst du nicht direkt auf den Link zu wenn er dir bekannt ist?
Am besten ist wenn du mir mal schreibst was dein Vorhaben ist, dann schaue ich mal wie das am besten geht, Vielleicht findet sich da eine andere / bessere Lösung als der API Aufruf.

ein beispiel wäre nicht schlecht.

Private Declare Sub UrlCombine Lib „shlwapi.dll“ Alias
„UrlCombineA“ _
(ByVal pszBase As String, ByVal pszRelative As String, ByVal
pszCombined As String, ByRef pcchCombined As Long, ByVal
dwFlags As Long)

MFG Alex

Mein Vorhaben.

Ich möchte einen Spider / Robot schrieben der eine Start URL ansurft und von dieser Start URL alle links herausfilter sich diese merk und dann die gefundenen links ansurft und diese nach links durchsucht. unm diese dann zu untersuchen.

nun giebt es aber volgende methoden um links anzugeben z.b. (alles nur beispiel mir sind die links nicht bekannt!)

http://www.website.de“ oder „www.website.de“ oder auch „http://website.de

und „./dokument.html“ oder „/dokument.html“ oder „dokument.html“ d.h
das ziel auf das sich der link bezieht liegt im selben verzeichnis wie die .html oder .php usw. datei

und „…/…/dokument.html“ d.h. das ziel auf das sich der link bezieht liegt zwei verzeichnis oberhalb wie die datei die den link enthält.

eine bessere und ausfürlichere erklärung evtl unter
http://de.selfhtml.org/html/verweise/index.htm
falls dir die html kentnisse nicht bekannt sein sollten
OK! weiter

Also müsste dein link auf der seite
www.website.de/html/doku.html
der „…/doku2.html“ heist
diese url ergeben „www.website.de/doku2.html

nun habe ich die URLCombine fnk. entdekt und bekomme sie nicht zum laufen. also bin ich nun schon soweit gegangen das ich mir heute nachmittag meine eingene fn.k geschieben habe URL_Combine code siehe unten.

da dich das tehma ja nun auch gegriffen hat wäre ein feedback von dir und allen anderen natürlich auch sehr schon und weitere tipps auch.

DER CODE…

Function URL_Combine(base_url As String, hlink_url As String) As String

Dim DIR() As String
Dim DIR_Anz As Integer
Dim DIR_zaehler As Integer
Dim s_Pos As Integer
Dim e_Pos As Integer
Dim new_hlink_Anfang As Integer
Dim new_hlink_DIR As String
Dim n As Integer

'base_url muss mit http:// beginnen
If Not Left$(base_url, 7) = „http://“ Then base_url = „http://“ & base_url

'Anzahl der verzeichnisse zählen
s_Pos = 8
Do
s_Pos = InStr(s_Pos, base_url, „/“)
If Not s_Pos = 0 Then
DIR_Anz = DIR_Anz + 1
s_Pos = s_Pos + 1
End If
Loop Until s_Pos = 0

ReDim DIR(1 To DIR_Anz)

'Base_url in alle einzelnen verzeichnisse bis zum root aufteilen
s_Pos = 8
DIR_zaehler = 0
Do
e_Pos = InStr(s_Pos, base_url, „/“)
If Not e_Pos = 0 Then
DIR_zaehler = DIR_zaehler + 1
DIR(DIR_zaehler) = Mid$(base_url, s_Pos, e_Pos - s_Pos)
s_Pos = e_Pos + 1
End If
Loop Until e_Pos = 0

'liegt das ziel im selben oder einenem unter verzeichniss ( „./“ oder „/“ )
If Left$(hlink_url, 1) = „/“ Then
URL_Combine = „http://“
For n = 1 To DIR_Anz
URL_Combine = URL_Combine & DIR(n) & „/“
Next n
URL_Combine = URL_Combine & Right$(hlink_url, Len(hlink_url) - 1)
Exit Function
End If
If Left$(hlink_url, 2) = „./“ Then
URL_Combine = „http://“
For n = 1 To DIR_Anz
URL_Combine = URL_Combine & DIR(n) & „/“
Next n
URL_Combine = URL_Combine & Right$(hlink_url, Len(hlink_url) - 2)
Exit Function
End If

'SONDERFALL z.b.: hlink_url = „dokument.html“
'd.h. ziel liegt im selben verzeichnis
If Not Left$(hlink_url, 1) = „/“ Then
If Not Left$(hlink_url, 2) = „./“ Then
If Not Left$(hlink_url, 3) = „…/“ Then
If Not Left$(hlink_url, 7) = „http://“ Then
If Not Left$(hlink_url, 4) = „www.“ Then
URL_Combine = „http://“
For n = 1 To DIR_Anz
URL_Combine = URL_Combine & DIR(n) & „/“
Next n
URL_Combine = URL_Combine & hlink_url
Exit Function
End If
End If
End If
End If
End If

'NEIN das ziel ligt in einem übergeordnetem verzeichnis

'wieviel dir soll nach oben gesprungen werden
s_Pos = 1
Do
If Mid$(hlink_url, s_Pos, 3) = „…/“ Then
DIR_Anz = DIR_Anz - 1
s_Pos = s_Pos + 3
'wo beginnt der eigentliche link verweis
new_hlink_Anfang = s_Pos
Else
Exit Do
End If
Loop

If DIR_Anz