我正在使用VBA代码从网站提取信息到excel单元格,数字信息是好的,但我有一个文本字符串的问题。我主要是从格鲁吉亚网站上提取信息,而格鲁吉亚语言的文本在excel中不能正确显示,所以我想知道是否有任何机会(代码或其他东西)我可以将这些符号转换为适当的语言。
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这是我从youtube视频(https://www.youtube.com/watch?v=IOzHacoP-u4)中摘取的代码,稍作修改后就可以工作了,我只是对excel如何显示文本字符串中的字符有个问题。

发布于 2021-07-13 10:38:51
在问题中为您的问题提供
由于it's required.
response = StrConv(request.responseBody, vbUnicode) to response = StrConv(request.responseBody, vbUnicode)在comment中为您的问题创建
要检索属性的ID,可以从类id-container中检索它,但是需要执行一些字符串处理来删除提取的:
propertyID = Trim$(Replace(html.getElementsByClassName("id-container")(0).innerText, ":", vbNullString))
注意:您应该尽量避免将变量声明为Variant。innerText属性返回String数据类型,因此应将address和price声明为String。
https://stackoverflow.com/questions/68344008
复制相似问题