首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在excel中将陌生字符和符号转换为普通语言

在excel中将陌生字符和符号转换为普通语言
EN

Stack Overflow用户
提问于 2021-07-12 16:11:47
回答 1查看 94关注 0票数 1

我正在使用VBA代码从网站提取信息到excel单元格,数字信息是好的,但我有一个文本字符串的问题。我主要是从格鲁吉亚网站上提取信息,而格鲁吉亚语言的文本在excel中不能正确显示,所以我想知道是否有任何机会(代码或其他东西)我可以将这些符号转换为适当的语言。

代码语言:javascript
复制
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如何显示文本字符串中的字符有个问题。

EN

回答 1

Stack Overflow用户

发布于 2021-07-13 10:38:51

在问题中为您的问题提供

由于it's required.

  • Change response = StrConv(request.responseBody, vbUnicode) to
  1. ,请删除此行response = StrConv(request.responseBody, vbUnicode)

在comment中为您的问题创建

要检索属性的ID,可以从类id-container中检索它,但是需要执行一些字符串处理来删除提取的:

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

注意:您应该尽量避免将变量声明为VariantinnerText属性返回String数据类型,因此应将addressprice声明为String

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68344008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档