我认为使用jQuery是可能的,但任何ASP.NET服务器端代码也适用于我的情况。
使用jQuery,我可以加载一个页面,例如div,并过滤div为<title>标签,但我认为对于重页面,首先阅读所有内容然后读取标题标签是不好的..或者也许它有一个非常简单的解决方案? 无论如何,我无法从互联网上找到任何相关信息。 谢谢
I think it's possible with jQuery, but any ASP.NET serverside code is good for my situation too.
With jQuery I can load a page to for example a div, and filter the div for <title> tag, but I think for heavy pages, it is not good to first read all of the content and then read the title tag.. or maybe it has a very simple solution? anyways I couldnt find anything about that from internet. thanks
最满意答案
好的,感谢cjjer和Boo,我刚刚阅读了有关正则表达式的更多内容,最后下面的代码对我有用。
Dim qq As New System.Net.WebClient Dim theuri As New Uri(TextBox1.Text) Dim res As String = qq.DownloadString(theuri) Dim re As Regex = New Regex("<title\b[^>]*>(.*?)</title>", RegexOptions.Singleline) Dim ma As Match = re.Match(res) If Not ma Is Nothing And ma.Success Then Response.Write(ma.Groups(1).Value.ToString()) Else Response.Write("error") End If但无论如何,问题仍然存在,这段代码正在下载整个页面并通过它寻找,其中一个重型网站花了超过2或3秒才完成,但似乎这是我所知道的唯一方法: 有什么建议可以改进这段代码吗?
okay thanks to cjjer and Boo, I've just read more about regex and finally the code below is working for me.
Dim qq As New System.Net.WebClient Dim theuri As New Uri(TextBox1.Text) Dim res As String = qq.DownloadString(theuri) Dim re As Regex = New Regex("<title\b[^>]*>(.*?)</title>", RegexOptions.Singleline) Dim ma As Match = re.Match(res) If Not ma Is Nothing And ma.Success Then Response.Write(ma.Groups(1).Value.ToString()) Else Response.Write("error") End Ifbut anyways, the problem remains, this code is downloading the whole page and seeking through it, which one heavy websites it took more than 2 or 3 secconds to complete, but seems it is the only way as far as I know :| Is there any suggestions to refine this code?
更多推荐
发布评论