C#确定给定网站的HTML链接
如果我在给定的网站上,有给定的完整URL,我如何确定任何href或src属性的绝对路径 因此,如果我有:C#确定给定网站的HTML链接,c#,C#,如果我在给定的网站上,有给定的完整URL,我如何确定任何href或src属性的绝对路径 因此,如果我有: string WebsiteImAt = "http://www.w3schools.com/media/media_mimeref.asp?q=1&s=2,2#a" //Just some random website with a sub path and a filename string text = DownloadHTML(WebsiteImAt); string h
string WebsiteImAt = "http://www.w3schools.com/media/media_mimeref.asp?q=1&s=2,2#a"
//Just some random website with a sub path and a filename
string text = DownloadHTML(WebsiteImAt);
string href = "/something/somethingelse/filename.asp";
//Should go to http://www.w3schools.com/something/somethingelse/filename.asp
string href2 = "something.asp";
//Should go to http://www.w3schools.com/media/something.asp
string href3 = "something";
//Should go to http://www.w3schools.com/media/something
我很难让我的正则表达式与“/诸如此类”一起工作,只是在没有斜杠的情况下“诸如此类”:
String value = Regex.Replace(text, "<(.*?)(src|href)=\"(?!http)(.*?)\"(.*?)>", "<$1$2=\"" + absoluteUrl + "$3\"$4>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
return value.Replace(WebsiteImAt + "/", WebsiteImAt);
String value=Regex.Replace(text,“,”,RegexOptions.IgnoreCase | RegexOptions.Multiline);
返回值.Replace(WebsiteImAt+“/”,WebsiteImAt);
我无法更改每个href/src以解析为正确的地址。如何修复我的正则表达式以解释上述三种情况