17. november 2002 - 12:52Der er
6 kommentarer og 1 løsning
æ ø å ?!?!
Jeg har fundet den her færdife kode, til at parse <TITLE> og META DESCIOTION fra en anden hjemmeside. Det virker fint, bare ikke når der kommer et æ, ø eller å de bliver erstattet med ?
Koden:
<% ' HTML Parser ' ' Has ability to retrieve a document from another web site and parse meta data ' such as Title, Description, and Keywords.
Class clsHTMLParser ' ------------------------------------------------------------------------------ Private mStrHTML Private mObjRegExp Private mObjMatches Private mObjMatch Public Title Public Keywords Public Description ' ------------------------------------------------------------------------------ Public Property Let HTML(ByRef pStrHTML) mStrHTML = pStrHTML
Set mObjRegExp = New RegExp mObjRegExp.IgnoreCase = True
Set mObjMatch = Nothing Set mObjMatches = Nothing Set mObjRegExp = Nothing
End Property ' ------------------------------------------------------------------------------ Public Property Get HTML() HTML = mStrHTML End Property ' ------------------------------------------------------------------------------ Private Sub ParseTitle() Title = "" mObjRegExp.Pattern = "<TITLE>([^<]*)</TITLE>" Set mObjMatches = mObjRegExp.Execute(mStrHTML) If mObjMatches.Count = 0 Then Exit Sub Title = mObjMatches.item(0).Value Title = Replace(Title, "<TITLE>", "", 1, -1, vbTextCompare) Title = Replace(Title, "</TITLE>", "", 1, -1, vbTextCompare) End Sub ' ------------------------------------------------------------------------------ Private Sub ParseDescription() Description = "" mObjRegExp.Pattern = "<META[^>]+(name=""description""|content=""([^""]*)"")[^>]+(name=""description""|content=""([^""]*)"")[^>]*>" Set mObjMatches = mObjRegExp.Execute(mStrHTML) If mObjMatches.Count = 0 Then Exit Sub Description = mObjMatches.item(0).Value Description = Mid(Description, InStr(1, Description, "content=""", vbTextCompare) + 9) Description = Mid(Description, 1, InStr(1, Description, """", vbTextCompare) -1) End Sub ' ------------------------------------------------------------------------------ Private Sub ParseKeywords() Keywords = "" mObjRegExp.Pattern = "<META[^>]+(name=""keywords""|content=""([^""]*)"")[^>]+(name=""keywords""|content=""([^""]*)"")[^>]*>" Set mObjMatches = mObjRegExp.Execute(mStrHTML) If mObjMatches.Count = 0 Then Exit Sub Keywords = mObjMatches.item(0).Value Keywords = Mid(Keywords, InStr(1, Keywords, "content=""", vbTextCompare) + 9) Keywords = Mid(Keywords, 1, InStr(1, Keywords, """", vbTextCompare) -1) End Sub ' ------------------------------------------------------------------------------ Public Function GetURL(ByRef pStrURL)
Dim lObjSpider Dim strText
If pStrURL = "" Then Exit Function
On Error Resume Next
' Different variations of XML objects 'Set lObjSpider = Server.CreateObject ("MSXML2.XMLHTTP.3.0") 'Set lObjSpider = Server.CreateObject ("MSXML2.ServerXMLHTTP") Set lObjSpider = Server.CreateObject ("Microsoft.XMLHTTP")
' Could not create Internet Control If Err Then GetURL = "Error: " & Err.Description Exit Function End If
On Error Goto 0
With lObjSpider .Open "GET", pStrURL, False, "", "" .Send GetURL = .ResponseText End With Set LobjSpider = Nothing
HTML = GetURL
End Function ' ------------------------------------------------------------------------------ End Class ' ------------------------------------------------------------------------------ %>
du kunne evt. i dine trim-fuktioner erstatte evt. æ,ø og å med en kombination af bogstaver eks "wyxw" og så substituere tilbage når du læser fra DB... ved godt der er lidt af en krejler løsning :-)
Jeg kan ikke. ... få det til at virke - snøft ;-( Håber en ekspert kan hjælpe mig !!
Min Kode: <% Session.LCID = 1030 ' ------------------------------------------------------------------------------ Class clsHTMLParser ' ------------------------------------------------------------------------------ Private mStrHTML Private mObjRegExp Private mObjMatches Private mObjMatch Public Title Public Keywords Public Description ' ------------------------------------------------------------------------------ Public Property Let HTML(ByRef pStrHTML) mStrHTML = pStrHTML
Set mObjRegExp = New RegExp mObjRegExp.IgnoreCase = True
Set mObjMatch = Nothing Set mObjMatches = Nothing Set mObjRegExp = Nothing
End Property ' ------------------------------------------------------------------------------ Public Property Get HTML() HTML = mStrHTML HTML = Replace(HTML,"æ","æ") HTML = Replace(HTML,"Æ","Æ") HTML = Replace(HTML,"ø","ø") HTML = Replace(HTML,"Ø","Ø") HTML = Replace(HTML,"å","å") HTML = Replace(HTML,"Å","Å") End Property ' ------------------------------------------------------------------------------ Private Sub ParseTitle() Title = "" mObjRegExp.Pattern = "<TITLE>([^<]*)</TITLE>" Set mObjMatches = mObjRegExp.Execute(mStrHTML) If mObjMatches.Count = 0 Then Exit Sub Title = mObjMatches.item(0).Value Title = Replace(Title, "<TITLE>", "", 1, -1, vbTextCompare) Title = Replace(Title, "</TITLE>", "", 1, -1, vbTextCompare) Title = Replace(Title,"æ","æ") Title = Replace(Title,"Æ","Æ") Title = Replace(Title,"ø","ø") Title = Replace(Title,"Ø","Ø") Title = Replace(Title,"å","å") Title = Replace(Title,"Å","Å") End Sub ' ------------------------------------------------------------------------------ Private Sub ParseDescription() Description = "" mObjRegExp.Pattern = "<META[^>]+(name=""description""|content=""([^""]*)"")[^>]+(name=""description""|content=""([^""]*)"")[^>]*>" Set mObjMatches = mObjRegExp.Execute(mStrHTML) If mObjMatches.Count = 0 Then Exit Sub Description = mObjMatches.item(0).Value Description = Mid(Description, InStr(1, Description, "content=""", vbTextCompare) + 9) Description = Mid(Description, 1, InStr(1, Description, """", vbTextCompare) -1)
Description = Replace(Description,"æ","æ") Description = Replace(Description,"Æ","Æ") Description = Replace(Description,"ø","ø") Description = Replace(Description,"Ø","Ø") Description = Replace(Description,"å","å") Description = Replace(Description,"Å","Å") End Sub ' ------------------------------------------------------------------------------ Private Sub ParseKeywords() Keywords = "" mObjRegExp.Pattern = "<META[^>]+(name=""keywords""|content=""([^""]*)"")[^>]+(name=""keywords""|content=""([^""]*)"")[^>]*>" Set mObjMatches = mObjRegExp.Execute(mStrHTML) If mObjMatches.Count = 0 Then Exit Sub Keywords = mObjMatches.item(0).Value Keywords = Mid(Keywords, InStr(1, Keywords, "content=""", vbTextCompare) + 9) Keywords = Mid(Keywords, 1, InStr(1, Keywords, """", vbTextCompare) -1) End Sub ' ------------------------------------------------------------------------------ Public Function GetURL(ByRef pStrURL)
Dim lObjSpider Dim strText
If pStrURL = "" Then Exit Function
On Error Resume Next
' Different variations of XML objects 'Set lObjSpider = Server.CreateObject ("MSXML2.XMLHTTP.3.0") 'Set lObjSpider = Server.CreateObject ("MSXML2.ServerXMLHTTP") Set lObjSpider = Server.CreateObject ("Microsoft.XMLHTTP")
' Could not create Internet Control If Err Then GetURL = "Error: " & Err.Description Exit Function End If
On Error Resume Next
With lObjSpider .Open "GET", pStrURL, False, "", "" .Send GetURL = .ResponseText End With Set LobjSpider = Nothing
HTML = GetURL
End Function ' ------------------------------------------------------------------------------ End Class ' ------------------------------------------------------------------------------ %>
Jeg tror den er gået lidt i stå her !! Jeg lukker og opretter nyt ??
Synes godt om
Ny brugerNybegynder
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.