打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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

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

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

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

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

最后用了以下方法解决

参考网页:

https://blog.csdn.net/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

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
delphi XE7 HttpEncode 编码问题 urlencode
钩天鹅图纸
Delphi中Ocx的动态注册方法
彩石奇石欣赏
CEF4Delphi 常用设置 CefSettings设置
CEF中弹出窗口的处理
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服