|
-
Dec 2nd, 2006, 10:42 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Get the root domain from a url?
Is there an API that can pull the root domain from a URL?
Or maybe a way to do it with the WebBrowser control?
Or am I going to have to think of some fancy string manipulation?
-
Dec 2nd, 2006, 10:48 PM
#2
Re: Get the root domain from a url?
String manipulation isn't hard. Just look for the third slash... that's the end of the root. Easy code to put together.
-
Dec 2nd, 2006, 11:36 PM
#3
Thread Starter
Frenzied Member
Re: Get the root domain from a url?
not completely right.
For examle"
http://by128fd.bay128.hotmail.msn.co...mbox=00xxxxxxx
the root is msn.com
But there are other, much stranger ways a url can be written.
-
Dec 2nd, 2006, 11:54 PM
#4
Re: Get the root domain from a url?
For that example, you could start at the third slash and work your way back to the 2nd . behind it.
You will also need to take into account that the user may not enter the http:// part. Or may leave out the www. And there may not be a slash after the domain name, ie: hotmail.msn.com.
-
Dec 3rd, 2006, 12:05 AM
#5
Thread Starter
Frenzied Member
Re: Get the root domain from a url?
 Originally Posted by DigiRev
For that example, you could start at the third slash and work your way back to the 2nd . behind it.
You will also need to take into account that the user may not enter the http:// part. Or may leave out the www. And there may not be a slash after the domain name, ie: hotmail.msn.com.
Exactly, that's why I'd like a nice reliable API or WebBrowser method.
It'd be a lot easier and cleaner than trying to think of all the possibilities
-
Dec 3rd, 2006, 12:08 AM
#6
Re: Get the root domain from a url?
 Originally Posted by longwolf
Exactly, that's why I'd like a nice reliable API or WebBrowser method.
It'd be a lot easier and cleaner than trying to think of all the possibilities
Well, it would be pretty simple string manipulation, it would just be a lengthy function, because you have to consider all possibilities.
To my knowledge, there is no API function for this. And there are no functions available in the WebBrowser control that will give you the root domain name.
I don't have a lot of experience with the WebBrowser control, though, so I could be wrong.
-
Dec 3rd, 2006, 12:20 AM
#7
Thread Starter
Frenzied Member
Re: Get the root domain from a url?
The WebBrowser control has a LOT to it, there just aren't any help files with it.
There are several API calls for working with URLs, and it seems like I saw one once for doing this.
But I can't find it now.
I'm very good at string manipulation, I'm just hopeing for a better option here.
-
Dec 3rd, 2006, 12:35 AM
#8
Thread Starter
Frenzied Member
Re: Get the root domain from a url?
I found it.
VB Code:
Private Declare Function UrlGetPart Lib "shlwapi" Alias "UrlGetPartA" (ByVal pszIn As String, ByVal pszOut As String, pcchOut As Long, ByVal dwPart As Long, ByVal dwFlags As Long) As Long
oops, had the wrong URL, here's the right one:
http://planetsourcecode.com/vb/scrip...27444&lngWId=1
Last edited by longwolf; Dec 3rd, 2006 at 12:40 AM.
-
Dec 3rd, 2006, 12:36 AM
#9
Thread Starter
Frenzied Member
Re: Get the root domain from a url?
Beats the heck out a class file I found.
It was over 500 lines and that was with it using RegEX!!!!
-
Dec 3rd, 2006, 12:52 AM
#10
Re: [RESOLVED] Get the root domain from a url?
Nice find. Never knew that API function existed.
-
Dec 3rd, 2006, 01:03 AM
#11
Thread Starter
Frenzied Member
Re: [RESOLVED] Get the root domain from a url?
Just been playing with it.
I'll still have to do a little string work to get the root domain, but not much.
-
Dec 3rd, 2006, 09:32 AM
#12
Thread Starter
Frenzied Member
Re: [RESOLVED] Get the root domain from a url?
Turns out there's an easy way to get same thing from the WebBrowser too
VB Code:
Debug.Print wbrBrowser.Document.domain
-
Feb 18th, 2017, 05:19 PM
#13
Junior Member
Re: [RESOLVED] Get the root domain from a url?
Found a Good Simple Solution at http://vb6.info/internet/extract-root-url-url-string/
Overall pretty reliable and pretty short compared to other solutions.
at top of module:
Code:
Private Const CONST_HOSTNAME = 2
Private Declare Function UrlGetPart Lib "shlwapi" Alias "UrlGetPartA" (ByVal pszIn As String, ByVal pszOut As String, pcchOut As Long, ByVal dwPart As Long, ByVal dwFlags As Long) As Long
then
Code:
Public Function sRet(ByVal strUrl As String) As String
On Error GoTo oops:
Dim lngPtr As Long, lngLen As Long
Dim strSection As String, sTemp As String
If (Len(strUrl) = 0) Then Exit Function
strSection = Space$(260&)
lngLen = Len(strSection)
If (UrlGetPart(strUrl, strSection, lngLen, CONST_HOSTNAME, 0&) = 0) Then
sTemp = Left$(strSection, lngLen)
Else
sRet = "error"
Exit Function
End If
'to avoid issues with complicated sub domains, etc, split at second .
sTemp = sfuncRootFromSubDomains(sTemp)
sRet = sTemp
Exit Function
oops:
If err.Number <> 0 Then
Stop '
End If
End Function
Private Function sfuncRootFromSubDomains(ByVal sUrl As String) As String
On Error GoTo oops:
sUrl = Replace(sUrl, "http://", "") 'remove http and https
sUrl = Replace(sUrl, "https://", "")
sUrl = Replace(sUrl, "www.", "") 'remove www.
Dim sParts() As String: sParts = Split(sUrl, ".")
Dim iUpp As Integer: iUpp = UBound(sParts)
sUrl = (sParts(iUpp - 1) & "." & sParts(iUpp))
sfuncRootFromSubDomains = sUrl
Exit Function
oops:
If err.Number <> 0 Then
Stop '
End If
End Function
〘SCRAPER〙software that extracts, organizes and displays data from the web.
〘BOT〙software that automates and speeds up tasks on the web, mimicking human behavior.
-
Feb 18th, 2017, 05:20 PM
#14
Junior Member
Re: Get the root domain from a url?
The planet source code solution has been removed for some reason.
〘SCRAPER〙software that extracts, organizes and displays data from the web.
〘BOT〙software that automates and speeds up tasks on the web, mimicking human behavior.
-
Feb 18th, 2017, 08:20 PM
#15
Hyperactive Member
Re: [RESOLVED] Get the root domain from a url?
If post #12 is correct seems a lot simpler than post #13
-
Feb 18th, 2017, 09:42 PM
#16
Re: [RESOLVED] Get the root domain from a url?
couldn't you split by dots and take the last array element, then split again by slashes and take ... the 2nd?
-
Feb 18th, 2017, 10:50 PM
#17
Junior Member
Re: [RESOLVED] Get the root domain from a url?
yes that works IF a web browser is being used.
〘SCRAPER〙software that extracts, organizes and displays data from the web.
〘BOT〙software that automates and speeds up tasks on the web, mimicking human behavior.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|