Character error when using MSXML2

levifunk

New Member
Joined
Mar 14, 2011
Messages
20
I'm having a problem downloading data when the website uses foreign or special characters. In this case "Rübæus"

Here is my code:
Code:
Dim xmlhttp As New MSXML2.XMLHTTP50
Dim text1 As String
xmlhttp.Open "GET", "http://beeradvocate.com/beer/profile/1199/23474", False
xmlhttp.send
text1 = xmlhttp.responseText
Sheets("Sheet1").Cells(1, 1) = text1

If you look at what is written on Sheet 1, in the 4th line of text returned you'll see this:
title>Founders R￿- Founders Brewing Company - Grand Rapids, MI - BeerAdvocate /title>
<br>
<b>instead of:</b>
title>Founders R<b>übæus</b>- Founders Brewing Company - Grand Rapids, MI - BeerAdvocate /title>
<br>
It is obviously erroring when trying to write out the "ü"

Any thoughts?!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Yea, I tried various Content-Type settings, but it didn't change anythings. Let me know if you come up with any other ideas.
 
Upvote 0
Correct. Any time it shows up, it just shows the "￿". Is there a way to expand the characters it recognizes? or is that what the Content-Type was suppose to do?
 
Upvote 0
I saw it correctly in other instances, just not the title.

I used

xmlhttp.setRequestHeader "Content-Type", "text/html; Charset=iso-8859-1"

right above the "xmlhttp.send" line

And it should be a string.
 
Upvote 0
One way is by using responseBody instead of responseText. responseBody is an array of bytes from which you can build a string, like this:
Code:
Sub XMLHttp_Get()

    Dim XMLHttp As New MSXML2.XMLHttp
    Dim body As String, i As Long
    Dim title As String
    
    XMLHttp.Open "GET", "http://beeradvocate.com/beer/profile/1199/23474", False
    XMLHttp.send
    
    body = ""
    For i = 1 To Len(XMLHttp.responseBody)
        body = body & Chr(XMLHttp.responseBody(i))
    Next
    
    title = Mid(body, InStr(LCase(body), Replace("< title >", " ", "")), 30)
    Debug.Print title
    
    Sheets("Sheet1").Cells(1, 1) = title
    
End Sub
Note - without the spaces in the "< title >" string the forum tries to render it as HTML and messes up my post, hence the use of the Replace function to remove these spaces. In your code, replace this function call with "< title >" but without any spaces.
 
Upvote 0
I saw it correctly in other instances, just not the title.

I used

xmlhttp.setRequestHeader "Content-Type", "text/html; Charset=iso-8859-1"

right above the "xmlhttp.send" line

And it should be a string.

The closest I see it is showing:
"R&uuml ;b&aelig ;us" (I added the spaces)
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,521
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top