Delphi XE 10.2.3使用CEF4Delphi取网页元素时碰到 变问号?的处理

用CEF4Delphi取网页元素时碰到ElementInnerText里含有" "

比如网页源码里是"内容 "取出来显示就变成"内容?"

搜索大部分是说把" "替换成其它字符即可

但实际操作怎么也替换不了,就算变量为AnsiString也不行

最后用了以下方法解决

参考网页:

https://blog.youkuaiyun.com/qq_29683707/article/details/80860904

关于&nbsp空格转成正常空格‘ ’的方法

 1>先把字符串转码 let data = encodeURI(要转化的值)

 2>接下来替换掉&nbsp空格 data = data .replace(/%C2%A0/g,'%20');
 3>再转回来就ok了 data = decodeURI(data);

要用到encodeURI,找到Delphi版的

http://www.delphitop.com/html/zifuchuan/2599.html

 

方法1
user  Httpapp; 

HttpEncode(AnsiToUtf8('中文'));


方法2
uses
  IdURI;

..
begin
  S := TIdURI.URLEncode(str);
//
  S := TIdURI.URLDecode(str);
end;

使用方法2的TIdURI.URLEncode,程序出错,原因不明

使用方法1成功

直接 TmpTitle:= HTTPEncode(TmpTitle); 即可

但编译器提示警告

[dcc32 Warning] uMiniBrowser.pas(469): W1000 Symbol 'HTTPEncode' is deprecated: 'Use TNetEncoding.URL.Encode'
[dcc32 Warning] uMiniBrowser.pas(471): W1000 Symbol 'HTTPDecode' is deprecated: 'Use TNetEncoding.URL.Decode'
[dcc32 Hint] uMiniBrowser.pas(469): H2443 Inline function 'HTTPEncode' has not been expanded because unit 'System.NetEncoding' is not specified in USES list
[dcc32 Hint] uMiniBrowser.pas(471): H2443 Inline function 'HTTPDecode' has not been expanded because unit 'System.NetEncoding' is not specified in USES list

 

意思是HTTPEncode和HTTPDecode已经弃用请用TNetEncoding.URL.Encode和TNetEncoding.URL.Decode

点进HTTPEncode看看

function HTTPDecode(const AStr: string): string;
begin
  Result := TNetEncoding.URL.Decode(AStr);
end;

function HTTPEncode(const AStr: string): string;
begin
  Result := TNetEncoding.URL.Encode(AStr);
end;

其实就直接调用了

TNetEncoding.URL.Encode

所在单元是 System.NetEncoding

 

转载于:https://www.cnblogs.com/samvon/p/10086475.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值