0

I am using the VBA code to extract information from a website into excel cells, and the numerical information is fine but I have a problem with text strings. I am mostly extracting information from Georgian websites, and the texts with the Georgian language are not properly displayed in excel, so I was wondering if there is any chance (code or something else) I could convert these symbols into proper language.

Sub GetData()

Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim price As Variant
Dim address As Variant
Dim x As Integer
Dim y As Range

x = 1
Do Until x = 9
    Set y = Worksheets(1).Range("A21:A200"). _
    Find(x, LookIn:=xlValues, lookat:=xlWhole)
    website = "https://www.myhome.ge/ka/pr/11247371/iyideba-Zveli-ashenebuli-bina-veraze-T.-WoveliZis-qucha"
    
' Create the object that will make the webpage request.
Set request = CreateObject("MSXML2.XMLHTTP")

' Where to go and how to go there.
request.Open "GET", website, False

' Get fresh data.
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"

' Send the request for the webpage.
request.send

' Get the webpage response data into a variable.
response = StrConv(request.responseBody, vbUnicode)

' Put the webpage into an html object.
html.body.innerHTML = response

' Get info from the specified element on the page.
address = html.getElementsByClassName("address").Item(0).innerText
price = html.getElementsByClassName("d-block convertable").Item(0).innerText
  
y.Offset(0, 1).Value = address
y.Offset(0, 5).Value = price

x = x + 1

Loop

End Sub

This is the code that I took from a youtube video (https://www.youtube.com/watch?v=IOzHacoP-u4) and slightly modified, and it works, I just have a problem with how excel displays the characters in text strings.

enter image description here

6
  • 3
    Please show a minimal reproducible example of your issue. Without code, it is very hard to help you. Commented Jul 12, 2021 at 8:16
  • 2
    @gugu - You don't need this line response = StrConv(request.responseBody, vbUnicode), Just assign responsetext to the innerhtml, html.body.innerHTML = request.responseText Commented Jul 12, 2021 at 9:32
  • 1
    Thank you very much @RaymondWu, your answer was extremely helpful and simple. I have been looking for this everywhere. Thank you again. Commented Jul 12, 2021 at 10:04
  • 2
    @gugu - I don't see anything in the code relating to ID (I only see address and price?) so I'm not exactly sure why your "code" is not working. But assuming I'm correct in reading the website, try Trim$(Replace(html.getElementsByClassName("id-container")(0).innerText, ":", vbNullString)). In your example this would return : 11247371 which I have applied Replace and Trim$ functions to process the result. Commented Jul 12, 2021 at 13:24
  • 1
    It worked. Thank you again very much. Commented Jul 12, 2021 at 13:36

1 Answer 1

1

For your issue in the question

  1. Remove this line response = StrConv(request.responseBody, vbUnicode) as it's not required.
  2. Change html.body.innerHTML = response to html.body.innerHTML = request.responseText.

For your issue in comment

To retrieve the ID of the property, it can be retrieved from the class id-container, you will need to perform some string processing though to remove the extract :

propertyID = Trim$(Replace(html.getElementsByClassName("id-container")(0).innerText, ":", vbNullString))

Note: You should try to avoid declaring variable as Variant. innerText property returns a String datatype so you should declare address and price as String.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.