C# 使用HtmlAlityPack获取html img元素的宽度
我正试图获得一个带有HtmlAgility包的img标签的值,比如C# 使用HtmlAlityPack获取html img元素的宽度,c#,asp.net,html-agility-pack,C#,Asp.net,Html Agility Pack,我正试图获得一个带有HtmlAgility包的img标签的值,比如 HtmlAgilityPack.HtmlAttribute width = link.Attributes["width"]; HtmlAgilityPack.HtmlAttribute height = link.Attributes["height"]; 但是这个返回50像素。然而,我只需要50就可以转换成数字。请提供任何帮助。对你来说不是int.Parse(value.Replac
HtmlAgilityPack.HtmlAttribute width = link.Attributes["width"];
HtmlAgilityPack.HtmlAttribute height = link.Attributes["height"];
但是这个返回50像素。然而,我只需要50就可以转换成数字。请提供任何帮助。对你来说不是
int.Parse(value.Replace(“px”,string.Empty”)
好吗?如果有px
后缀,它将在解析之前消失,如果没有,这很酷,我们可以直接解析为整数。int.parse(value.Replace(“px”,string.Empty))对您来说不是很好吗?如果有px
后缀,它将在解析之前消失,如果没有,这很酷,我们可以直接解析为一个整数。@AlexeiLevenkov,非常简单,通过链接.Replace
方法:value.Replace(“px”,string.Empty)。Replace(“em”,string.Empty)。Replace(“%”,string.Empty)
。有用的注释。。。(我的评论不是很严肃——虽然50px
本身有一定的意义,1em
和其他相关度量在没有上下文的情况下不会给出有用的结果)@AlexeiLevenkov,非常简单,通过链接.Replace
方法:value.Replace(“px”,string.Empty)。Replace(“em”,string.Empty)。Replace(“%,string.Empty”)有用的评论…(我的评论不是很严肃-虽然50px
本身有一定的意义,1em
和其他相关测量在没有上下文的情况下不会给出有用的结果)